<xsl:comment> Element

Generates a comment in the output.


Element Information

Number of occurrences


Parent elements

xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

Child elements

xsl:apply-imports, xsl:apply-templates, xsl:call-template, xsl:choose, xsl:copy, xsl:copy-of, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:number, xsl:text, xsl:value-of, xsl:variable


The text generated by the children of <xsl:comment> appears between the starting characters (<!--) and the closing characters (-->).


In the following example, the news.xsl style sheet transforms the news.xml document, and inserts a comment into the XSLT output.

XML File (news.xml)

<?xml version ="1.0"?>
<?xml-stylesheet type="text/xsl" href="news.xsl"?>
<story1>Here is the top news story.</story1>
    <story2> Here is the next news story.</story2>

XSLT File (news.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="/">
<xsl:comment>insert top news story</xsl:comment>
<xsl:value-of select="//story1"/>



This is the formatted output:

Here is the top news story.

This is the processor output:

<BODY><!--insert top news story-->
<P>Here is the top news story.</P>