The <xsl:comment> Element: Generating Comments

You can also create comments on the fly with the <xsl:comment> element. This element has no attributes and encloses a template body that sets the text of the comment.

In the following example, I’m creating comments that are to replace <PLANET> elements, and I’ll include the name of the planet in the text of the comment:

Listing 6.8. Using <xsl:comment>
 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="PLANETS"> <HTML> <HEAD> <TITLE> Planets </TITLE> </HEAD> <BODY> <xsl:apply-templates select="PLANET"/> </BODY> </HTML> </xsl:template> <xsl:template match="PLANET"> <xsl:comment>This was the <xsl:value-of select="NAME"/> element</xsl:comment> ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.