I have variable 'temperatureQualifier' whose type is array. I need to read that array variable and extract each value from the array and use it in my XSLT.
Sample Input XML is
<document>
<item>
<gtin>1000909090</gtin>
<flex>
<attrGroupMany name="tradeItemTemperatureInformation">
<row>
<attr name="temperatureQualifier">[10, 20, 30, 40]</attr>
</row>
</attrGroupMany>
</flex>
</item>
</document>
Desired Output XML should be
<?xml version="1.0" encoding="UTF-8"?>
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>Item_Master_TRADEITEM_TEMPERATURE_MVL</RelationType>
<RelatedItems>
<Attribute name="code">
<Value>10</Value>
</Attribute>
<Attribute name="code">
<Value>20</Value>
</Attribute>
<Attribute name="code">
<Value>30</Value>
</Attribute>
<Attribute name="code">
<Value>40</Value>
</Attribute>
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
I am using the below XSLT but it is giving me all values in 1 node only.
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="document">
<CatalogItem>
<RelationshipData>
<Relationship>
<RelationType>Item_Master_TRADEITEM_TEMPERATURE_MVL</RelationType>
<RelatedItems>
<xsl:for-each select="item/flex/attrGroupMany[@name ='tradeItemTemperatureInformation']/row">
<Attribute name="code">
<Value>
<xsl:value-of select="attr[@name='temperatureQualifier']"/>
</Value>
</Attribute>
</xsl:for-each>
</RelatedItems>
</Relationship>
</RelationshipData>
</CatalogItem>
</xsl:template>
</xsl:stylesheet>
Note: Number of value in array can be 1 or more than 1. Example for single value array is [10]
Example for multie value array is [10, 20, 30, 40]