<html>
<head>
<title>&lt;xsl:comment&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:comment&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
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 <span class="LITERAL">&lt;xsl:comment&gt;</span> element is the generation of CSS definitions or JavaScript code in an HTML document.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Category</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Instruction</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Required Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optional Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Content</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>An XSLT template.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Appears in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>
<span class="LITERAL">&lt;xsl:comment&gt;</span> appears in a template.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT section 7.4, Creating Comments. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Here's a stylesheet that generates a comment to define CSS styles in an HTML document:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="html"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;XSLT and CSS Demo&lt;/title&gt;
        &lt;style&gt;
          &lt;xsl:comment&gt; 
            p.big      {font-size: 125%; font-weight: bold} 
            p.green    {color: green; font-weight: bold}
            p.red      {color: red; font-style: italic}
          &lt;/xsl:comment&gt;
        &lt;/style&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;xsl:apply-templates select="list/title"/&gt;
        &lt;xsl:apply-templates select="list/listitem"/&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="title"&gt;
    &lt;p class="big"&gt;&lt;xsl:value-of select="."/&gt;&lt;/p&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="listitem"&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test="position() mod 2"&gt;
        &lt;p class="green"&gt;&lt;xsl:value-of select="."/&gt;&lt;/p&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;p class="red"&gt;&lt;xsl:value-of select="."/&gt;&lt;/p&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  
&lt;/xsl:stylesheet&gt;</pre></span>
<p>This stylesheet creates three CSS styles inside an HTML comment.  We'll apply the stylesheet to this document:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;list xml:lang="en"&gt;
  &lt;title&gt;Albums I've bought recently:&lt;/title&gt;
  &lt;listitem&gt;The Sacred Art of Dub&lt;/listitem&gt;
  &lt;listitem&gt;Only the Poor Man Feel It&lt;/listitem&gt;
  &lt;listitem&gt;Excitable Boy&lt;/listitem&gt;
  &lt;listitem xml:lang="sw"&gt;Aki Special&lt;/listitem&gt;
  &lt;listitem xml:lang="en-gb"&gt;Combat Rock&lt;/listitem&gt;
  &lt;listitem xml:lang="zu"&gt;Talking Timbuktu&lt;/listitem&gt;
  &lt;listitem xml:lang="jz"&gt;The Birth of the Cool&lt;/listitem&gt;
&lt;/list&gt;</pre></span>
<!--<?troff .Nd 10?>-->
<p>The stylesheet will apply one CSS style to the <span class="LITERAL">&lt;title&gt;</span> element and will alternate between two CSS styles for the <span class="LITERAL">&lt;listitem&gt;</span>s.  Here's the generated HTML:</p>
<span class="PROGRAMLISTING"><pre>
&lt;html&gt;
&lt;head&gt;
&lt;META http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
&lt;title&gt;XSLT and CSS Demo&lt;/title&gt;
&lt;style&gt;
&lt;!-- 
            p.big      {font-size: 125%; font-weight: bold} 
            p.green    {color: green; font-weight: bold}
            p.red      {color: red; font-style: italic}
          --&gt;
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p class="big"&gt;Albums I've bought recently:&lt;/p&gt;
&lt;p class="green"&gt;The Sacred Art of Dub&lt;/p&gt;
&lt;p class="red"&gt;Only the Poor Man Feel It&lt;/p&gt;
&lt;p class="green"&gt;Excitable Boy&lt;/p&gt;
&lt;p class="red"&gt;Aki Special&lt;/p&gt;
&lt;p class="green"&gt;Combat Rock&lt;/p&gt;
&lt;p class="red"&gt;Talking Timbuktu&lt;/p&gt;
&lt;p class="green"&gt;The Birth of the Cool&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></span>
<p>When rendered, the document looks like <link linkend="xslt-appa-a6">Figure A-6</link>.</p>
<figure label="A-6" id="xslt-appa-a6">
        <p class="TITLE">Document with generated comment nodes</p>
        <graphic depth="323" width="405" fileref="figs/xslt.aa06.gif"/>
      </figure>
</td>
</tr>
</table>
</div>
</body>
</html>