Beispiel 4 von <xsl:if>
In diesem Beispiel wird der Text "International Stock
" eingefügt, wenn das <stock>
-Element über ein Attribut mit dem Namen international
verfügt.
XML-Datei (stock.xml)
<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="ifstock.xsl" ?>
<stocks>
<stock international="yes">Microsoft</stock>
<stock>Wingtip Toys</stock>
<stock international="yes">Contoso Pharmaceuticals</stock>
<stock>Contoso, Ltd</stock>
<stock international="yes">Fabrikam, Inc.</stock>
</stocks>
XSLT-Datei (ifstock.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:apply-templates/>
</body></html>
</xsl:template>
<xsl:template match="stock">
<p/>
<xsl:if test="@international">International Stock </xsl:if>
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Ausgabe
Dies ist die formatierte Ausgabe:
International Stock Microsoft
Wingtip Toys
International Stock Contoso Pharmaceuticals
Contoso, Ltd
International Stock Fabrikam, Inc.
Im Folgenden wird die Prozessorausgabe dargestellt, wobei aus Gründen der Übersichtlichkeit Zeilenumbrüche hinzugefügt wurden.
<html><body>
<p></p>International Stock Microsoft
<p></p>Wingtip Toys
<p>
...
</p>International Stock Fabrikam, Inc.
</body></html>
Siehe auch
Konzepte
Beispiel 1 von <xsl:if>
Beispiel 2 von <xsl:if>
Beispiel 3 von <xsl:if>