Name

<xsl:comment>

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.

Category

Instruction.

Required Attributes

None.

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.

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.”

Example

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" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>XSLT and CSS Demo</title>
        <style>
          <xsl:comment> 
            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 O’Reilly online learning.

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