I have an xml Template and a input XML file. I have to create an output XML file using the template and populating values from the input XML file. Any help or pointing to an example will be much appreciated since I havent used XML with perl.
Perl because thats the preferred coding language. Template.xml (10.1 KB) InputFile.XML (106.3 KB)
Attached for your reference
Thank you for your help in advance
example xsl template (aka transformation) , gaunTransform.xsl (1.5 KB)
This 'template' is used to 'transform' data in a given format into ... data in another format using the template specified within. Obviously the input must at some point map to the template.
Key elements involved in the 'transformation' <xsl:for-each select="/people/person"> - will iterated over the entire input file trying to match on groupings <xsl:if test="some-element-field-name"> takes an element value if the element is defined within the current
<xsl:for-each select="job-history/job"> - iterates across all entries within the current
There are a couple of 'placeholder' fields in the .xsl (, ) merely to demonstrate that fields can be added to the output even though not existing in the incoming data file.
Likewise there are fields in the incoming data file that have not been mapped (for demo purposes - in the example.
Hopefully this simple example can help . The 'hard' work is getting a record definition from your raw input data (which i struggled to map back to what you supplied, hence me generating this), into a xsl format such that it can then read the input and transform into the appropriately formatted output.
NB: I referenced the following whilst attempting this.
XML in a nutshell (chapter 8) XSL Transformations ,
and
NB: NO PERL was referenced , ultimately if the input can be mapped onto an xslt transform then there's little need to use perl or anything else - since xsltproc will do the heavy lifting.
@gaun , thanks for responding. Sharing your solution (partial or otherwise) would be great, why - one of the primary tenets of the forum is to share knowledge, that way everyone benefits from the efforts of others be it directly or indirectly.