|
Subject: Re: [xsl] commenting an XML element [XSLT 1.0][xsltproc] From: Martin Honnen <Martin.Honnen@xxxxxx> Date: Wed, 18 Aug 2010 13:09:13 +0200 |
Hello all,
I am trying to comment one of the empty element (<spec/>) in my xml tree but seems I am missing something.
My stylesheet look something below:
<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>
This is what I get using xsltproc (MAC)
Error: element text misplaced text element
Any ideas please.
PS: I do have my identity transform defined in stylesheet.
<root> <spec foo="bar"><baz/></spec> <spec>--</spec> </root>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template><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>runtime error: file test2010081801Xsl.xml line 12 element comment xsl:comment : '--' or ending '-' not allowed in comment
Martin Honnen http://msmvps.com/blogs/martin_honnen/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] commenting an XML element [XS, pankaj . c | Thread | Re: [xsl] commenting an XML element, Wolfgang Laun |
| [xsl] commenting an XML element [XS, pankaj . c | Date | Re: [xsl] commenting an XML element, Wolfgang Laun |
| Month |