Thank you for your response, however i am looking to use some sort of a generic code as my actual xml file has a lot of fields with similar rules to be implemented, am trying to use tokenize but it isn't working as expected. Also i wouldn't like to explicity check for the ITEM_PAY2VENDOR_INFO tag as this could be varying in the input xml.
<?xml version="1.0" encoding="UTF-8"?>
<Message externalVersion="2.6" >
<Header>
<PartyName>INT</PartyName>
<ShortName>INT</ShortName>
</Header>
<Body>
<Document subtype="CatEditAdd" type="CatEdit">
<ItemData>
<Attribute name="PRODUCTID">
<Value>171</Value>
</Attribute>
<Attribute name="ITEM_PAY2VENDOR">
<Value/>
</Attribute>
<Attribute name="ITEM_PAY2VENDOR_INFO">
<Value>[{CHI_BUY=, COWNERTYPE=-1, CSOURCE_PREFERENCE=2}]</Value>
</Attribute>
</ItemData>
</Document>
</Body>
</Message>
xsl code that i have been using
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<ItemData>
<xsl:for-each select="Message/Body/ItemData/Attribute">
<xsl:variable name="Value" select="string( . )" />
<xsl:variable name="Attr" select="string('@name')" />
<xsl:if test = "Attr = 'ITEM_PAY2VENDOR_INFO'">
<xsl:variable name="tokenizedSample" select="tokenize($Value,',')"/>
<xsl:for-each select= "tokenizedSample">
<xsl:variable name= "tokenizedPairs">
<xsl:value-of select= "tokenize('.,', '=')"/>
</xsl:variable>
<xsl:for-each select="$tokenizedPairs">
<xsl:element name="{$tokenizedPairs[1] }">
<xsl:value-of select="$tokenizedPairs[2]" />
</xsl:element>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</ItemData>
</xsl:template>
</xsl:stylesheet>
<!--outputExpected.xml>
<?xml version="1.0" encoding="UTF-8"?>
<ItemData>
<PRODUCTID>171</PRODUCTID>
<ITEM_PAY2VENDOR></ITEM_PAY2VENDOR>
<ITEM_PAY2VENDOR_INFO>
<CHI_BUY></CHI_BUY>
<COWNERTYPE>-1</COWNERTYPE>
<CSOURCE_PREFERENCE>2</CSOURCE_PREFERENCE>
</ITEM_PAY2VENDOR_INFO>
</ItemData>
|