August 2001
Intermediate to advanced
480 pages
11h 16m
English
<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 the generation of CSS definitions or JavaScript code in an HTML document.
Instruction
None.
None.
An XSLT template.
<xsl:comment> appears in a template.
XSLT section 7.4, Creating Comments.
Here’s a stylesheet that generates a comment to define CSS styles in an HTML document:
<?xml version="1.0"?>
<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.green {color: green; font-weight: bold}
p.red {color: red; font-style: italic}
</xsl:comment>
</style>
</head>
<body>
<xsl:apply-templates select="list/title"/>
<xsl:apply-templates select="list/listitem"/>
</body>
</html>
</xsl:template>
<xsl:template match="title">
<p class="big"><xsl:value-of select="."/></p>
</xsl:template>
<xsl:template match="listitem">
<xsl:choose>
<xsl:when test="position() mod 2">
<p class="green"><xsl:value-of select="."/></p>
</xsl:when>
<xsl:otherwise>
<p class="red"><xsl:value-of select="."/></p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>This stylesheet creates three ...