<xsl:comment> | |
Diese Anweisung ermöglicht die Erstellung eines Kommentars im Ausgabedokument. Kommentare werden manchmal verwendet, um juristische Hinweise, Ausschlussklauseln oder Erstellungsinformationen über das Ausgabedokument aufzunehmen. Eine weitere praktische Anwendung des Elements <xsl:comment> ist die Erzeugung von CSS-Definitionen oder JavaScript-Code in einem HTML-Dokument. | |
Kategorie | |
Anweisung |
|
Obligatorische Attribute | |
Keine |
|
Optionale Attribute | |
Keine |
|
Inhalt | |
Eine XSLT-Vorlage |
|
Übergeordnetes Element | |
<xsl:comment> erscheint innerhalb einer Vorlage. |
|
Definition | |
XSLT-Abschnitt 7.4, Erzeugung von Kommentaren |
|
Beispiel | |
Es folgt ein Stylesheet, das einen Kommentar für die Definition von CSS-Formaten in einem HTML-Dokument definiert: <?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> Dieses Stylesheet erzeugt drei CSS-Formate innerhalb eines HTML-Kommentars. Das Stylesheet wird auf das folgende Dokument angewendet: <?xml version="1.0"?> <list xml:lang="en"> <title>Albums I've bought recently:</title> <listitem>The Sacred Art of Dub</listitem> <listitem>Only the Poor Man Feel It</listitem> <listitem>Excitable Boy</listitem> <listitem xml:lang="sw">Aki Special</listitem> <listitem xml:lang="en-gb">Combat Rock</listitem> <listitem xml:lang="zu">Talking Timbuktu</listitem> <listitem xml:lang="jz">The Birth of the Cool</listitem> </list> Das Stylesheet wendet ein CSS-Format auf das Element <title> an und wechselt zwischen zwei CSS-Formaten für die Listenelemente (<listitem>). Hier der erzeugte HTML-Code: <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>XSLT and CSS Demo</title> <style> <!-- p.big {font-size: 125%; font-weight: bold} p.green {color: green; font-weight: bold} p.red {color: red; font-style: italic} --> </style> </head> <body> <p class="big">Albums I've bought recently:</p> <p class="green">The Sacred Art of Dub</p> <p class="red">Only the Poor Man Feel It</p> <p class="green">Excitable Boy</p> <p class="red">Aki Special</p> <p class="green">Combat Rock</p> <p class="red">Talking Timbuktu</p> <p class="green">The Birth of the Cool</p> </body> </html> Wie das HTML-Dokument in einem Browser angezeigt wird, sehen Sie in Abbildung A-6. Dokument mit erzeugten Kommentarknoten |