以下のサンプルは、数値データ(出来高)により条件分岐し色分けしている。
[サンプルXML文書を表示](下のフレームに)
XMLソース
<?xml version="1.0" encoding="Shift_JIS" ?> <?xml-stylesheet type="text/xsl" href="choose02.xsl"?> <start> <top>2000年12月27日の東証株式第一部株式情報</top> <contents> <kabu><name>松下</name><end>2600</end><total>1658</total></kabu> <kabu><name>松下寿</name><end>1780</end><total>16</total></kabu> <kabu><name>シャープ</name><end>1388</end><total>1487</total></kabu> <kabu><name>ソニー</name><end>7900</end><total>1017</total></kabu> <!-- ・・・・途中省略・・・--> <kabu><name>光通信</name><end>1931</end><total>53</total></kabu> </contents> <end>以上です(01/1/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="/"> <center><H3><xsl:value-of select="start/top"/></H3></center> <xsl:apply-templates select="start/contents"/> </xsl:template> <xsl:template match="start/contents"> <table border="2"> <tr><th>銘柄</th><th>終値</th><th>出来高</th></tr> <xsl:for-each select="kabu"> <xsl:choose> <xsl:when test="total[.$gt$ 3000]"> <tr style="background-color:black;color:white;font-weight:bold"> <td><xsl:value-of select="name" /></td> <td style="text-align:right"><xsl:value-of select="end" /></td> <td style="text-align:right"><xsl:value-of select="total" /></td> </tr> </xsl:when> <xsl:when test="total[.$gt$ 2000 and .$lt$ 2999]"> <tr style="background-color:silver;color:navy"> <td><xsl:value-of select="name" /></td> <td style="text-align:right"><xsl:value-of select="end" /></td> <td style="text-align:right"><xsl:value-of select="total" /></td> </tr> </xsl:when> <xsl:when test="total[.$gt$ 1000 and .$lt$ 1999]"> <tr style="color:red;font-weight:bold"> <td><xsl:value-of select="name" /></td> <td style="text-align:right"><xsl:value-of select="end" /></td> <td style="text-align:right"><xsl:value-of select="total" /></td> </tr> </xsl:when> <xsl:when test="total[.$gt$ 500 and .$lt$ 999]"> <tr> <td><xsl:value-of select="name" /></td> <td style="text-align:right"><xsl:value-of select="end" /></td> <td style="text-align:right;font-weight:bold"><xsl:value-of select="total" /></td> </tr> </xsl:when> <xsl:otherwise> <tr> <td><xsl:value-of select="name" /></td> <td style="text-align:right"><xsl:value-of select="end" /></td> <td style="text-align:right"><xsl:value-of select="total" /></td> </tr> </xsl:otherwise> </xsl:choose> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
end(01/1/16)