[xsl] commenting an XML element [XSLT 1.0][xsltproc]

Subject: [xsl] commenting an XML element [XSLT 1.0][xsltproc]
From: pankaj.c@xxxxxxxxxxxxxxxxxx
Date: Wed, 18 Aug 2010 16:22:57 +0530
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="'&lt;'"/>
            <xsl:value-of select="name()"/>
        <xsl:value-of select="'&gt;'"/>
            <xsl:apply-templates select="@*|node()" mode="comment" />
        <xsl:value-of select="'&lt;/'"/>
            <xsl:value-of select="name()"/>
        <xsl:value-of select="'&gt;'"/>
    </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.

TIA,
Pankaj

Current Thread