Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Reference

<xsl:comment> Element

Generates a comment in the output.

<xsl:comment>
</xsl:comment>

Element Information

Number of occurrences Unlimited
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

Remarks

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

Example

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

Note To test this example, you need to use a script. For more information, see Initiate XSLT in a Script.

XML File (news.xml)

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

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="/">
<HTML>
<BODY>
<xsl:comment>insert top news story</xsl:comment>
<P>
<xsl:value-of select="//story1"/>
</P>
</BODY>
</HTML>
</xsl:template>

</xsl:stylesheet>

Output

This is the formatted output:

Here is the top news story.

This is the processor output:

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

See Also

Generating Comments, Processing Instructions, and Elements

Other Resources Other Resources

Internet Explorer Tools for Validating XML and Viewing XSLT Output