xml - Retrieve global XSLT variables anywhere -
how can merge following/consecutive value parameters output master card 1234.
xml:
<customfieldlist> <customfield> <name>paymentcardtype1</name> <value>master card</value> </customfield> <customfield> <name>carddisplaynumber1</name> <value>1234</value> </customfield> name>paymentcardtype2</name> <value>gift card</value> </customfield> <customfield> <name>carddisplaynumber2</name> <value>6789</value> </customfield> </customfieldlist>
xslt:
<xsl:for-each select="/cxml/message/customfieldlist"> <xsl:for-each select="/cxml/message/customfieldlist/customfield"> .... </xsl:for-each> </xsl:for-each>
can create custom tags store payment types , numbers
<payment1>master card 1234</payment1> <payment2>gift card 6789</payment2>
try this:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="customfieldlist"> <xsl:for-each select="customfield[starts-with(name,'paymentcardtype')]"> <xsl:variable name ="nr" select="substring-after(name,'paymentcardtype')" /> <xsl:element name="{concat('payment', $nr)}" > <xsl:value-of select="value"/> <xsl:text> </xsl:text> <xsl:value-of select="../customfield[name =concat('carddisplaynumber', $nr)]/value"/> </xsl:element> </xsl:for-each> </xsl:template> </xsl:stylesheet>
otuput:
<payment1>master card 1234</payment1> <payment2>gift card 6789</payment2>
Comments
Post a Comment