Reputation: 1002
We have a complex Adobe LiveCycle XDP (XFA) for Appraiser Application Form with XML Data Model (default one, nothing fancy). There is another XDP of the same Application Form, same layout, but with different model and XML Structure. The XML Structure of the 2nd form is based on format which I am not familiar with, but I can understand what is in there.
The 1st XML is plain vanilla XML, straight forward.
The 2nd XML has multiple nested sections, and the field names are specified in the attribute of the tag element. The images are specified in the attachment section, and the are references from the relevant tag element.
Following is a sample of the 1st XML:
<app_rep1>
<NEW_primaryform>Some-primary-form</NEW_primaryform>
<NEW_TITLE_PHOTO>SamplePhotoLabel1</NEW_TITLE_PHOTO>
<NEW_CITY>Toronto</NEW_CITY>
<NEW_Stage>Stage Value</NEW_Stage>
<NEW_GS_AGE>23</NEW_GS_AGE>
<NEW_POOL_X>Nice Pool</NEW_POOL_X><NEW_PHOTO1>/9j/4AAQSkZJRgABAAEASABIAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCE
bla...bla...bla
</NEW_PHOTO1>
</app_rep1>
Following is a sample of the 2nd XML:
<app_rep2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.1">
<appraisal>
<configuration>
<primaryform>Some-primary-form</primaryform>
<versioninfo>
<acifileversion>123</acifileversion>
<collectionversion>1.2.3.4</collectionversion>
<collection>Report Pro</collection>
<platform>Desktop Platform</platform>
</versioninfo>
</configuration>
<data>
<form name="photo1" primary="false">
<section type="other" number="0" name="section_name1">
<tag name="TITLE_PHOTO">SamplePhotoLabel1</tag>
<tag name="LINE_PHOTO">SamplePhotoDescription1</tag>
</section>
<tag name="PHOTO1">../../../attachments/attachment[@key='267463fa-0073-4c10-83d6-fd8141641b72']</tag>
</form>
<form name="Some-primary-form" primary="true">
<section type="other" number="0" name="OPTIONS">
<tag name="OPT_TYPE_OF_APPRAISAL">Appraisal Type Value</tag>
</section>
<section type="subject" number="0" name="SUBJECT">
<tag name="CITY">Toronto</tag>
<tag name="STATE">Stage Value</tag>
<tag name="GS_AGE">23</tag>
<tag name="POOL_X">Nice Pool</tag>
</section>
</form>
</data>
<attachments>
<attachment type="photo" label="" key="267463fa-0073-4c10-83d6-fd8141641b72">
<image>
<binary format="jpeg">/9j/4AAQSkZJRgABAAEASABIAAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCE
bla...bla...bla
</binary>
</image>
</attachment>
</attachments>
</appraisal>
</app_rep2>
As you can see, I want to transform the 2nd XML to look like the 1st XML.
I think I need to first write the XSLT. Then, I need to import the 2nd XML into the 1st XDP, and apply the XSLT while importing.
Am I thinking in the right direction?
Can you please help achieve my goal? I am not exactly sure how to do that.
Questions:
How to develop the XSLT?
How to apply the XSLT while merging the 2nd XML with the 1st XDP? How I can do than using Acrobat? How I can do that using Adobe LiveCycle Process Management?
How I can perform the mapping of field names from XML 1 to XML 2? There are more than 1000 fields. I can prepare list of pairs in Excel File (field_name_1, field_name_2), but how I can apply the find/replace using the list as input? So, step 1 will be to apply transformation with the wrong field names, then step 2 will apply the find/replace.
Any help would be appreciated.
Thanks, Tarek
Upvotes: 0
Views: 550
Reputation: 29052
Concerning the first part of your question, you can simply extract the values from your XML with this XSLT-1.0 stylesheet. The problem with the NEW_PHOTO1
element is that the dynamic evaluation of an XPath is only possible in XSLT-3.0 with the xsl:evaluate
function (and IIRC you even need the commercial version of Saxon or another processor that supports it). And I don't know about the extension library you mentioned.
But if you can hardcode the base path /app_rep2/appraisal/attachments/attachment
, you can match the key from the tag
element with the key attribute of the attachment
element. This is not elegant, but may save you troubles depending on your whole scenario.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="app_rep2">
<app_rep1>
<NEW_primaryform><xsl:value-of select="appraisal/configuration/primaryform" /></NEW_primaryform>
<NEW_TITLE_PHOTO><xsl:value-of select="appraisal/data/form[@name='photo1']/section/tag[@name='TITLE_PHOTO']" /></NEW_TITLE_PHOTO>
<NEW_CITY><xsl:value-of select="appraisal/data/form[@name='Some-primary-form']/section[@type='subject']/tag[@name='CITY']" /></NEW_CITY>
<NEW_Stage><xsl:value-of select="appraisal/data/form[@name='Some-primary-form']/section[@type='subject']/tag[@name='STATE']" /></NEW_Stage>
<NEW_GS_AGE><xsl:value-of select="appraisal/data/form[@name='Some-primary-form']/section[@type='subject']/tag[@name='GS_AGE']" /></NEW_GS_AGE>
<NEW_POOL_X><xsl:value-of select="appraisal/data/form[@name='Some-primary-form']/section[@type='subject']/tag[@name='POOL_X']" /></NEW_POOL_X>
<xsl:variable name="key" select='substring-before(substring-after(appraisal/data/form[@name="photo1"]/tag[@name="PHOTO1"],"@key='"),"'")' />
<NEW_PHOTO1><xsl:value-of select="/app_rep2/appraisal/attachments/attachment[@type='photo' and @key=$key]/image/binary" /></NEW_PHOTO1>
</app_rep1>
</xsl:template>
</xsl:stylesheet>
The output matches your first file. How to integrate that with Adobe - I don't know...
Upvotes: 1