I need an xslt transform that would convert an xml generated by one aplication and sent to another application to be processed. Below is a sample source xml containing data field names and their relevant data like 'current_date','item'..for field names and '18-OCT-2018','1044103',.. for data values.
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<labels _JOBNAME="LBL1273711">
<label>
<variable name= "current_date">18-OCT-2018</variable>
<variable name= "item">1044103</variable>
<variable name= "item_description">RING,22-16 AWG,#4,RED,PB FREE</variable>
<variable name= "locator">INRE</variable>
</label>
</labels>
The above xml is to transformed as the below xml:
<XMLScript Version="1.0">
<Command>
<Print JobName="LBL1273711">
<RecordSet Name="Text File 1" Type="btTextFile" AddIfNone="true">
<TextData><![CDATA[
current_date", "item", "item_description", "locator"
"18-OCT-2018", "1044103", "RING,22-16 AWG,#4,RED,PB FREE", "INRE"
]]></TextData>
</RecordSet>
</Print>
</Command>
</XMLScript>
The data field names, the field count and their values would vary and change from one incoming xml to another.I'm using the below xslt in one requirement where the field names and the field count are hardcoded. But I need it to be changed to transform the source xml of any number of field count and field names provided in the variable/name.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" cdata-section-elements="TextData"/>
<xsl:template match="/labels">
<XMLScript Version="1.0">
<Command>
<Print JobName="{@_JOBNAME}">
<RecordSet Name="Text File 1" Type="btTextFile" AddIfNone="true">
<TextData>
<xsl:value-of select="concat('
'
,'current_date','", "','item','", "',
'item_description','", "','locator','"
')" />
<xsl:for-each select="label">
<xsl:value-of select="concat('"',
variable[@name='current_date'],'", "',
variable[@name='item'],'", "',
variable[@name='item_description'],'", "',
variable[@name='locator'],'"
'
)" />
</xsl:for-each>
</TextData>
</RecordSet>
</Print>
</Command>
</XMLScript>
</xsl:template>
</xsl:stylesheet>
Thanks in advance.