|
Subject: Re: [xsl] commenting an XML element [XSLT 1.0][xsltproc] From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Wed, 18 Aug 2010 13:36:24 +0200 |
On 18/08/2010 12:09, Martin Honnen wrote:I don't see any problem with that code
The code is trying to copy elements into a comment, but comments can not conatin element nodes, they only have a text value, not children (the same as attributes).
You need to serialise the element to a string (either using a template usineg <<xsl:value-of select="name()"/>.... or an extension such as saxon:serialize().
<xsl:template match="spec">
<xsl:comment>
<xsl:apply-templates select="self::*" mode="comment"/>
</xsl:comment>
</xsl:template> <xsl:template match="*" mode="comment">
<xsl:value-of select="'<'"/>
<xsl:value-of select="name()"/>
<xsl:value-of select="'>'"/>
<xsl:apply-templates select="@*|node()" mode="comment" />
<xsl:value-of select="'</'"/>
<xsl:value-of select="name()"/>
<xsl:value-of select="'>'"/>
</xsl:template> <xsl:template match="text()" mode="comment">
<xsl:value-of select="."/>
</xsl:template> <xsl:template match="@*" mode="comment">
<xsl:value-of select="name()"/>
<xsl:text>="</xsl:text>
<xsl:value-of select="."/>
<xsl:text>" </xsl:text>
</xsl:template>Martin Honnen http://msmvps.com/blogs/martin_honnen/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] commenting an XML element, David Carlisle | Thread | Re: [xsl] commenting an XML element, David Carlisle |
| Re: [xsl] commenting an XML element, Martin Honnen | Date | Re: [xsl] commenting an XML element, David Carlisle |
| Month |