The xsl:comment element is used to generate a comment in the output.
The purpose of a comment is simply to provide information that may be of interest or importance to human users of the code. For example, you could list information about the program itself, such as the date of creation and programmer names or catalog changes and corrections. Carefully placed comments can also be used to debug code.
In one regard, the ability to comment in XSL is far more sophisticated than the ability to comment in other languages such as HTML and VBScript. Like other elements in XSL, the xsl:comment element can make use of extension functions and can contain functions. While this may be of limited use for a comment, you can do things like include date-time stamps in your comment as demonstrated in this code fragment:
<xsl:comment>
<xsl:value-of select="Date:toString()" />
</xsl:comment>
This element has no attributes. It is not a self-closing tag. The separate closing element is mandatory.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:comment>Written on 4/24/2001 by the Guru</xsl:comment>
<xsl:for-each select="devguru_staff/programmer">
NAME: <xsl:value-of select="name" />
<br />
</xsl:for-each>
</body>
</html>
</xsl:template>
</stylesheet>
<html>
<body><!--Written on 4/24/2001 by the Guru-->
NAME: Bugs Bunny<br>
NAME: Daisy Duck<br>
NAME: Minnie Mouse<br>
NAME: Pluto<br>
NAME: Porky Pig<br>
NAME: Road Runner<br></body>
</html>
This is the code for xslt_example_comment.xsl.In this example, we place a comment stating when and who wrote the code, and we list the names of the DevGuru staff members.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_comment.xsl"?>