Allows you to create a comment in the output document. Comments are sometimes used to add legal notices, disclaimers, or information about when the output document was created. Another useful application of the <xsl:comment> element is generating CSS definitions or JavaScript code in an HTML document.



Required Attributes


Optional Attribute

[2.0] select

An XPath expression that generates content for the comment. If this attribute is not present, the contents of the <xsl:comment> element are used instead. If the select attribute is not present and the <xsl:comment> element is empty, an empty comment is generated. It is a fatal error for an <xsl:comment> element to have a select attribute and contain content.


A [1.0] node-set or [2.0] sequence constructor.

Appears in

<xsl:comment> appears in a template.

Defined in

[1.0] XSLT section 7.4, “Creating Comments.”

[2.0] XSLT section 11.8, “Creating Comments.”


Here’s a stylesheet that generates a comment to define CSS styles in an HTML document:

<?xml version="1.0"?>
<!-- comment.xsl -->
<xsl:stylesheet version="1.0" 

  <xsl:output method="html"/>

  <xsl:template match="/">
        <title>XSLT and CSS Demo</title>
            p.big   {font-size: 125%; font-weight: bold;} 
            p.odd   {color: purple; font-weight: bold;}
            p.even  {color: blue; font-style: italic; font-weight: bold;}
          </xsl:comment> </style> </head> <body style="font-family: ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.