■基本的な処理の流れ
(xsl内容)
<xsl:template match="/">
<xsl:apply-templates select="ノードA"/>
・・・(a)
<xsl:apply-templates select="ノードB"/>
・・・(b)
</xsl:template>
<xsl:template match="ノードA">
・・・(aa)
処理内容
</xsl:template>
<xsl:template match="ノードB">
・・・(bb)
処理内容
</xsl:template>
・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・
1) プラウザは(a)で、xml文書内を上から順番に探し、"ノードA"が見つかると(aa)のテンプレート定義内容に従い処理する。
2)さらにxml文書内をサーチし"ノードA"が見つかる度に、(aa)のテンプレート定義内容に従い処理していく。
3)次に、(b)で、xml文書内を上から順番に探し、"ノードB"が見つかると(bb)のテンプレート定義内容に従い処理する。
4)さらにxml文書内をサーチし"ノードB"が見つかる度に、(bb)のテンプレート定義内容に従い処理していく。
★特記
・対応するテンプレート定義内容<xsl:template >が複数ある場合、一番最後に記述されているものが適応される。
・テンプレート指定<xsl:apply-templates>の記述順に処理され表示されていく。テンプレート定義内容<xsl:template
>の記述位置や順番は表示に関係しない。
[サンプルXML文書を表示](下のフレームに)
XMLソース
<?xml version="1.0" encoding="Shift_JIS" ?> <?xml-stylesheet type="text/xsl" href="xsl04.xsl"?> <start> <title>KodayanHomepageのサイト構成</title> <top> <web>CSSとDynamicHTML</web> <pc>大阪日本橋DOS/Vプロムナード</pc> <web>XMLって?</web> <web>PerlでCGI</web> <pc>日本橋DOS/Vショップ一覧</pc> <web>Java Applet</web> <oth>お気に入りLinks</oth> <web>Java Script</web> <oth>その他</oth> </top> <end>以上です(01/3/13)</end> </start>
XSLソース
<?xml version="1.0" encoding="Shift_Jis"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <center><H3><xsl:value-of select="start/title"/></H3></center> <xsl:apply-templates select="start/top/pc"/> <xsl:apply-templates select="start/top/web"/> <xsl:apply-templates select="start/top/oth"/> <xsl:apply-templates select="start/top/pc"/> </xsl:template> <xsl:template match="web"> <p style="color:red"><xsl:value-of /></p> </xsl:template> <xsl:template match="oth"> <p style="color:blue"><xsl:value-of /></p> </xsl:template> <xsl:template match="pc"> <p style="color:pink"><xsl:value-of /></p> </xsl:template> <xsl:template match="pc"> <p style="color:green"><xsl:value-of /></p> </xsl:template> </xsl:stylesheet>
end(01/3/13)