Perl XML help needed

Hi,

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.

Thanks

@gaun , Why perl?

Can you show the template and a sample from the XML file ?

Is this related to your earlier post ?

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

@gaun , attached,

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.

  • sample xml data file data.xml (1.4 KB)

executing xsltproc gaunTransform.xsl data.xml > transformedResults.XML

produces: transformedResults.XML (1.3 KB)

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.

fire back with questions

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.

Thanks. I did use twig for my coding purpose and was able to achieve most of what was to be done

1 Like

@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.

tks

Sure I will once I code all the elements needed

1 Like