Escaping xml tag in XSLT -
i have input xml, say:
<myxml> <myelement id="1" /> <myelement id="2" /> <myelement id="3" /> </myxml>
i want create xslt creates output xml of different form, say:
<theirxml> <theirelement id="1" /> <theirelement id="2" /> <theirelement id="3" /> </theirxml>
since cannot create xslt tag inside tag (e.g. "<theirelement id="<xslt:...>" >" found way cdata follows (presented relevant part of xslt):
<xsl:for-each select="myxml/myelement"> <xsl:text><![cdata[<theirelement id="]]></xsl:text><xsl:value-of select="@name" /><xsl:text><![cdata[" />]]></xsl:text> </xsl:for-each>
however produced output not contain "<theirelement ..." rather "<theirelement ...". need output contain "<" , not "<" (same goes ">" , ">").
the reason, btw, because output process input program fails read xml when tags escaped "<tag>".
any appreciated!
here stylesheet desired transform:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output encoding="utf-8" method="xml"/> <xsl:template match="/"> <myxml> <xsl:apply-templates/> </myxml> </xsl:template> <xsl:template match="myelement"> <theirelement> <xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute> </theirelement> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment