I have a requirement where i need to generate a text file from XML document, generated text file should be in some particular format based on some rules. My XML looks something shown below:
<info>
<Tag1>
<Tag2>
<Tag3>
<PartNo>12 </PartNo>
</Tag3>
<DBOMInf1> 111 </DBOMInf1>
<DBOMInf2> sring </DBOMInf2>
</Tag2>
<Tag2>
<Tag3>
<PartNo>12 </PartNo>
</Tag3>
<DBOMInf1> 555 </DBOMInf1>
<DBOMInf2> abcd </DBOMInf2>
</Tag2>
</Tag1>
<Tag4>
<Tag5>
<Description>1200 liter </Description>
<No>12</No>
<Name>Engine</Name>
<Id>700</Id>
</Tag5>
</Tag4>
<action>
<actionId>700</actionId>
</action>
</info>
- Expected output format in text:
ACTIONID|NO|DESCRIPTION|NAME|DBOMInf1|DBOMInf2 700|12|Engine|1200 liter| 111|sring 700|12|Engine|1200 liter| 555|abcd
I am new to XSLT programming can any body share some info or example on how can i achieve this , i am familiar with basis of XSLT like templates matching, value of select.
Any link, or example will be very helpful. Thanks
It looks like you want a row for each Tag2 element, in which case these are easily matching by doing the following (assuming you are currently positioned on the info element
But it also looks like you want to look up information from Tag5 elements. In this case you could use a key to look up such values, based on the No element. The key would be defined as follows:
And to look up the tags for a given Tag2 element, you could do the following:
(Note, normalize-space with remove the excess white-space from the element)
Here is the full XSLT
When applied to your input XML, the following text is output