xml - Remove extra value using XSL -
how remove value being generated after transformation.
input:
<response status="200"> <idlist> <idlists> <idsec> <idfield> <idfields> <id>123456</id> <idstate>done</idstate> </idfields> <idfields> <id>12345634</id> <idstate>failed</idstate> </idfields> </idfield> </idsec> </idlists> <code>56</code> <msg>yet</msg> </idlist> </response>
xsl transforming it:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="/"> <xsl:if test="/response/idlist/idlists/idsec/idfield/idfields/id"> <xsl:apply-templates/> </xsl:if> </xsl:template> <xsl:template match="idfields"> <cid> <id> <xsl:value-of select="id"/> </id> <idstate> <xsl:value-of select="idstate"/> </idstate> </cid> </xsl:template> </xsl:stylesheet>
required output:
<cid> <id>123456</id> <idstate>done</idstate> </cid> <cid> <id>12345634</id> <idstate>failed</idstate> </cid>
generated output after using above xsl:
<cid> <id>123456</id> <idstate>done</idstate> </cid> <cid> <id>12345634</id> <idstate>failed</idstate> </cid>56yet
how remove 56yet output?
change
<xsl:template match="/"> <xsl:if test="/response/idlist/idlists/idsec/idfield/idfields/id"> <xsl:apply-templates/> </xsl:if> </xsl:template>
to
<xsl:template match="/"> <xsl:apply-templates select="/response/idlist/idlists/idsec/idfield/idfields[id]"/> </xsl:template>
Comments
Post a Comment