Skip to content

xsl:comment

Indicates text that is to be output to the current output stream in the form of an XML or HTML comment.

Available in XSLT 1.0 and later versions. Available in all Saxon editions.

  • Category: instruction
  • Content: sequence-constructor
  • Permitted parent elements: any XSLT element whose content model is sequence-constructor; any literal result element

Attributes

select?
expression
The content of the comment may be given either by a select attribute or by an enclosed sequence constructor. If the select attribute is used and the value is a sequence, then the items in the sequence are output space-separated.

Details

The xsl:comment element can appear anywhere within an xsl:template.

Note that special characters occurring within the comment text will not be escaped.

The xsl:comment element will normally contain text only but it may contain other elements such as xsl:if or xsl:value-of. However, it should not contain literal result elements.

Tip: the xsl:comment element can be very useful for debugging your stylesheet. Use comments in the generated output as a way of tracking which rules in the stylesheet were invoked to produce the output.

In XSLT 3.0, it is often convenient to construct comments using text value templates, for example <xsl:comment expand-text='yes'>Status: {$status}</xsl:comment>.

Examples

The text below inserts some JavaScript into a generated HTML document:

<script language="JavaScript">
  <xsl:comment>
      function bk(n) {
          parent.frames['content'].location="chap" + n + ".1.html";
      }
  //</xsl:comment>
</script>

Comments