Simple question. I have an XML file with a few dozens of comment blocks. This is being transformed by a stylesheet to generate an HTML page. However, the comments are ignored with this. But at the bottom of the generated HTML I would like to have a list of all comments within the XML file. Is that even possible, without the use of anything else than pure XSLT? (No Javascript or whatever!)
As far as I know, this is not possible, but I could be wrong...
The reason the comments aren't processed is that the default template for comments do nothing:
<xsl:template match="processing-instruction()|comment()"/>
See XSLT 1.0 spec "Built-in Template Rules".
If you would like to do something else with comments, you could just create your own matching template and output them as either a new XML comment using xsl:comment
or make a HTML list:
<xsl:template match="/">
<ul>
<xsl:apply-templates select="//comment()"/>
</ul>
</xsl:template>
<xsl:template match="comment()">
<li>
<xsl:value-of select="."/>
</li>
</xsl:template>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With