xsl-list
[Top] [All Lists]

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

2010-08-18 07:47:11
Thanks again Martin for looking into it.

I tried testing it with below stylesheet, now complete one but with same 
error. Something is terribly missing in code.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">

    <!--Identity transform copies all items by default -->
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="colspec">
        <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>

</xsl:stylesheet>

Just for reference, below is the sample xml


<?xml version="1.0" encoding="UTF-8"?>
<!-- New document created with EditiX at Wed Aug 18 17:37:11 IST 2010 -->
<root>
<table id="t0010" frame="topbot" rowsep="0" colsep="0">
<label>Table 3-1</label>
<caption>
<simple-para id="sp0200" role="title">This is a dummy title.</simple-para>
<simple-para id="sp0210">Ranjan</simple-para>
</caption>
<source>Source if present.</source>
<tgroup cols="2">
<colspec colname="col1"/>
<colspec colname="col1"/>
<colspec colname="col2"/>
<thead valign="top">
<row>
<entry rowsep="1" align="left">Abbreviation</entry>
<entry rowsep="1" align="left">Dosage Interval</entry>
</row>
</thead>
<!-- More code here 
-->
</tgroup>
</table>
</root>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--