・属性値により条件処理し、適用するclassスタイルを分ける。
[サンプルXML文書を表示](下のフレームに)
XMLソース
<?xml version="1.0" encoding="Shift_JIS" ?> <?xml-stylesheet type="text/xsl" href="style02.xsl"?> <start> <title>KodayanHomepageのサイト構成</title> <top> <web flg="1">大阪日本橋DOS/Vプロムナード</web> <web flg="2">CSSとDynamicHTML</web> <web flg="3">XMLって?</web> <web flg="1">PerlでCGI</web> <web flg="2">Java Applet</web> <web flg="3">Java Script</web> <web flg="1">VB Script</web> <web flg="2">お気に入りLinks</web> <web flg="3">その他</web> </top> <end>以上です(00/11/16)</end> </start>
XSLソース
<?xml version="1.0" encoding="Shift_Jis"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <html> <head> <title><xsl:value-of select="start/title"/></title> <style type="text/css"> .style1 {width:300;background-color:silver; color:red;border:thin solid blue} .style2 {width:300;background-color:yellow; color:blue;border:thin solid green} .style3 {width:300;background-color:pink; color:navy;border:thin solid red} </style> </head> <body> <center><H3><xsl:value-of select="start/title"/></H3></center> <xsl:apply-templates select="start/top"/> </body></html> </xsl:template> <xsl:template match="start/top"> <xsl:for-each select="web"> <xsl:choose> <xsl:when test="@flg[.='1']"> <H4 class="style1"><xsl:value-of /></H4> </xsl:when> <xsl:when test="@flg[.='2']"> <H4 class="style2"><xsl:value-of /></H4> </xsl:when> <xsl:otherwise> <H4 class="style3"><xsl:value-of /></H4> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:template> </xsl:stylesheet>
end(00/11/16)