テンプレートの選択的な適用
<xsl:apply-templates select="種類" />として、種類要素に対してだけ
テンプレートを適用した。名前要素のテンプレートは用意されているが、
適用されていない。
【sample005.xml】
<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet href="sample005.xsl" type="text/xsl"?>
<会社>
<名前>ジャムハウス</名前>
<種類>有限会社</種類>
</会社>
【sample005.xsl】
<?xml version="1.0" encoding="Shift_JIS" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Shift_JIS" />
<xsl:template match="会社">
<html>
<head><title>テンプレートの選択的な適用</title></head>
<body>
<h2>テンプレートの選択的な適用</h2>
<p>会社を発見しました</p>
<p style="color:red;">その値は<xsl:value-of select="." />です</p>
<xsl:apply-templates select="種類" />
</body>
</html>
</xsl:template>
<xsl:template match="名前">
<p>名前を発見しました</p>
<p style="color:red;">その値は<xsl:value-of select="." />です</p>
</xsl:template>
<xsl:template match="種類">
<p>種類を発見しました</p>
<p style="color:red;">その値は<xsl:value-of select="." />です</p>
</xsl:template>
</xsl:stylesheet>
【結果】