テンプレート指定<xsl:apply-templates>すれば、該当するnodeを再帰的にサーチしテンプレート処理していく。これを利用すれば”繰り返し処理”ができる。このサンプルでは繰り返し処理で表を生成しています。
[サンプルXML文書を表示](下のフレームに)
XMLソース
<?xml version="1.0" encoding="Shift_JIS" ?> <?xml-stylesheet type="text/xsl" href="xsl07.xsl"?> <start> <title>KodayanHomepage</title> <contents>サイト構成 <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>HP履歴</oth> <oth>掲示板</oth> <oth>お知らせ</oth> </contents> <end>以上です(01/4/5)</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> <TABLE border="2"> <xsl:apply-templates select="start/contents/pc"/> <xsl:apply-templates select="start/contents/web"/> <xsl:apply-templates select="start/contents/oth"/> </TABLE> </xsl:template> <xsl:template match="pc"> <TR><TD>●</TD> <TD><p style="color:blue"><xsl:value-of /></p></TD> </TR> </xsl:template> <xsl:template match="web"> <TR><TD>★</TD> <TD><p style="color:red"><xsl:value-of /></p></TD> </TR> </xsl:template> <xsl:template match="oth"> <TR><TD>☆</TD> <TD><p style="color:navy"><xsl:value-of /></p></TD> </TR> </xsl:template> </xsl:stylesheet>
end(01/4/5)