O'Reilly logo

Real World XML by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating Comments with xsl:comment

You can also create comments on the fly with the <xsl:comment> element. Here's an example. In this case, I'm creating comments that will replace <PLANET> elements. I'll include the name of the planet in the text of the comment:

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

<xsl:template match="PLANETS">
    <HTML>
        <HEAD>
            <TITLE>
                Planets
            </TITLE>
        </HEAD>
        <BODY>
            <xsl:apply-templates select="PLANET"/>
        </BODY>
    </HTML>
</xsl:template>

<xsl:template match="PLANET">
    <xsl:comment>This was the <xsl:value-of select="NAME"/> element</xsl:comment>
</xsl:template>

</xsl:stylesheet>

Here's the result:

 <HTML> <HEAD> <TITLE> Planets </TITLE> </HEAD> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required