処理<xsl:apply-templates /> 3

■<xsl:apply-templates />でselect属性を省略した場合、カレントnodeに含まれる全ての直接の子nodeを順次処理していく。対応するテンプレート<xsl:template>があればそのテンプレートに従い処理していく。対応するテンプレートが無い場合は、デフォルトのテンプレートが適用される(テキストノード,属性ノードの値をそのまま表示する,というもの)。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
★(このサンプルでは)カレントnodeは<start/top>
1)最初の子nodeは”サイト構成”というテキストnode。デフォルトテンプレートに従い、テキストがそのまま出力される。
2)以下<web>、<pc>という要素nodeが、定義されているテンプレートに従い処理されていく。
3)<oth>要素はテンプレートが定義されていない。デフォルトテンプレートに従い、テキストがそのまま出力される。ただし<oth/othx>の部分はテンプレートが定義されているので、それに従い出力される。

[サンプルXML文書を表示](下のフレームに)

XMLソース

<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet type="text/xsl" href="xsl05.xsl"?>
<start>
<title>KodayanHomepage</title>
<top>サイト構成
<web>CSSとDynamicHTML</web>
<pc>大阪日本橋DOS/Vプロムナード</pc>
<web>XMLって?</web>
<pc>日本橋DOS/Vショップ一覧</pc>
<oth>お気に入りLinks</oth>
<web>Java Script</web>
<oth>その他
<othx>HP履歴</othx>
<othy>掲示板</othy>
<othz>お知らせ</othz>
</oth>
</top>
<end>以上です(01/3/16)</end>
</start>

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="/">
<center><H3><xsl:value-of select="start/title"/></H3></center>
<xsl:apply-templates select="start/top"/>
</xsl:template>

<xsl:template match="start/top">
<xsl:apply-templates />
</xsl:template>

<xsl:template match="pc">
<p style="color:red"><xsl:value-of select="." /></p>
</xsl:template>
<xsl:template match="web">
<p style="color:navy"><xsl:value-of select="." /></p>
</xsl:template>
<xsl:template match="oth/othx">
<span style="color:magenta"><xsl:value-of select="." /></span>
</xsl:template>
</xsl:stylesheet>

end(01/3/16)