1.xsl:if
<
xsl:if
test
="逻辑表达式"
>
</ xsl:if >
</ xsl:if >
2.xsl:choose
<
xsl:choose
>
< xsl:when test ="逻辑表达式" >
</ xsl:when >
< xsl:when test ="逻辑表达式" >
</ xsl:when >
< xsl:otherwise >
</ xsl:otherwise >
</ xsl:choose >
< xsl:when test ="逻辑表达式" >
</ xsl:when >
< xsl:when test ="逻辑表达式" >
</ xsl:when >
< xsl:otherwise >
</ xsl:otherwise >
</ xsl:choose >
例子:
ex29.xml
<?
xml version="1.0" encoding="gb2312"
?>
<? xml-stylesheet type="text/xsl" href="ex29.xsl" ?>
< DOCUMENT >
< STOCK >
< NUMBER > 000868 </ NUMBER >
< NAME > 安凯客车 </ NAME >
< START > 7.10 </ START >
< END > 7.78 </ END >
< TRADE > 69295 </ TRADE >
</ STOCK >
< STOCK >
< NUMBER > 000720 </ NUMBER >
< NAME > 鲁能泰山 </ NAME >
< START > 19.00 </ START >
< END > 19.91 </ END >
< TRADE > 34445 </ TRADE >
</ STOCK >
< STOCK >
< NUMBER > 000099 </ NUMBER >
< NAME > 中信海直 </ NAME >
< START > 9.95 </ START >
< END > 9.83 </ END >
< TRADE > 120300 </ TRADE >
</ STOCK >
< STOCK >
< NUMBER > 000926 </ NUMBER >
< NAME > 福星科技 </ NAME >
< START > 12.14 </ START >
< END > 12.23 </ END >
< TRADE > 25678 </ TRADE >
</ STOCK >
</ DOCUMENT >
<? xml-stylesheet type="text/xsl" href="ex29.xsl" ?>
< DOCUMENT >
< STOCK >
< NUMBER > 000868 </ NUMBER >
< NAME > 安凯客车 </ NAME >
< START > 7.10 </ START >
< END > 7.78 </ END >
< TRADE > 69295 </ TRADE >
</ STOCK >
< STOCK >
< NUMBER > 000720 </ NUMBER >
< NAME > 鲁能泰山 </ NAME >
< START > 19.00 </ START >
< END > 19.91 </ END >
< TRADE > 34445 </ TRADE >
</ STOCK >
< STOCK >
< NUMBER > 000099 </ NUMBER >
< NAME > 中信海直 </ NAME >
< START > 9.95 </ START >
< END > 9.83 </ END >
< TRADE > 120300 </ TRADE >
</ STOCK >
< STOCK >
< NUMBER > 000926 </ NUMBER >
< NAME > 福星科技 </ NAME >
< START > 12.14 </ START >
< END > 12.23 </ END >
< TRADE > 25678 </ TRADE >
</ STOCK >
</ DOCUMENT >
ex29.xsl
<?
xml version="1.0" encoding="gb2312"
?>
< xsl:stylesheet version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
< xsl:template match ="/" >
< html >
< head >
< title ></ title >
</ head >
< body >
< p align ="center" >< font size ="7" > 股票价格表 </ font ></ p >
< table width ="90%" >
< tr >
< td width ="18%" >< div align ="center" > 编号 </ div ></ td >
< td width ="18%" >< div align ="center" > 简称 </ div ></ td >
< td width ="15%" >< div align ="center" > 开盘价 </ div ></ td >
< td width ="15%" >< div align ="center" > 收盘价 </ div ></ td >
< td width ="24%" >< div align ="center" > 成交量 </ div ></ td >
</ tr >
< xsl:for-each select ="//STOCK" >
<!-- 使用xsl:choose对每个股票进行相关测试 -->
< xsl:choose >
<!-- 股票价格在下跌 -->
< xsl:when test ="(END - START) div START < 0" >
< tr bgcolor ="#C0C0C0" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:when >
<!-- 股票涨幅在5%以内 -->
< xsl:when test ="(END - START) div START >= 0 and (END - START) div START < 0.05" >
< tr bgcolor ="#00FF00" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:when >
<!-- 股票涨幅在5%-10%之间 -->
< xsl:when test ="(END - START) div START >=0.05 and (END - START) div START < 0.10" >
< tr bgcolor ="#0000FF" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:when >
<!-- 默认情况,股票涨幅在10%以上 -->
< xsl:otherwise >
< tr bgcolor ="#FFFF00" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:otherwise >
</ xsl:choose >
</ xsl:for-each >
</ table >
< br />< br />
< p align ="left" >< font size ="4" > 灰色-股票正在下跌 </ font ></ p >
< p align ="left" >< font size ="4" > 绿色-股票涨幅在5%以内 </ font ></ p >
< p align ="left" >< font size ="4" > 蓝色-股票涨幅在5%到10%之间 </ font ></ p >
< p align ="left" >< font size ="4" > 黄色-股票涨幅在10%以上 </ font ></ p >
< p align ="left" >< font size ="4" > HOT标记-交易量超过100000手的股票 </ font ></ p >
</ body >
</ html >
</ xsl:template >
< xsl:template match ="NUMBER" >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="." /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../NAME" /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../START" /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../END" /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../TRADE" />
<!-- 如果采用xsl:if,如果股票交易量超过100000手,则加上HOT的标志 -->
< xsl:if test ="../TRADE >= 100000" > (HOT) </ xsl:if ></ div >
</ td >
</ xsl:template >
</ xsl:stylesheet >
< xsl:stylesheet version ="1.0" xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
< xsl:template match ="/" >
< html >
< head >
< title ></ title >
</ head >
< body >
< p align ="center" >< font size ="7" > 股票价格表 </ font ></ p >
< table width ="90%" >
< tr >
< td width ="18%" >< div align ="center" > 编号 </ div ></ td >
< td width ="18%" >< div align ="center" > 简称 </ div ></ td >
< td width ="15%" >< div align ="center" > 开盘价 </ div ></ td >
< td width ="15%" >< div align ="center" > 收盘价 </ div ></ td >
< td width ="24%" >< div align ="center" > 成交量 </ div ></ td >
</ tr >
< xsl:for-each select ="//STOCK" >
<!-- 使用xsl:choose对每个股票进行相关测试 -->
< xsl:choose >
<!-- 股票价格在下跌 -->
< xsl:when test ="(END - START) div START < 0" >
< tr bgcolor ="#C0C0C0" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:when >
<!-- 股票涨幅在5%以内 -->
< xsl:when test ="(END - START) div START >= 0 and (END - START) div START < 0.05" >
< tr bgcolor ="#00FF00" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:when >
<!-- 股票涨幅在5%-10%之间 -->
< xsl:when test ="(END - START) div START >=0.05 and (END - START) div START < 0.10" >
< tr bgcolor ="#0000FF" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:when >
<!-- 默认情况,股票涨幅在10%以上 -->
< xsl:otherwise >
< tr bgcolor ="#FFFF00" >< xsl:apply-templates select ="NUMBER" /></ tr >
</ xsl:otherwise >
</ xsl:choose >
</ xsl:for-each >
</ table >
< br />< br />
< p align ="left" >< font size ="4" > 灰色-股票正在下跌 </ font ></ p >
< p align ="left" >< font size ="4" > 绿色-股票涨幅在5%以内 </ font ></ p >
< p align ="left" >< font size ="4" > 蓝色-股票涨幅在5%到10%之间 </ font ></ p >
< p align ="left" >< font size ="4" > 黄色-股票涨幅在10%以上 </ font ></ p >
< p align ="left" >< font size ="4" > HOT标记-交易量超过100000手的股票 </ font ></ p >
</ body >
</ html >
</ xsl:template >
< xsl:template match ="NUMBER" >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="." /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../NAME" /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../START" /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../END" /></ div >
</ td >
< td style ="font-style:楷体_gb2312; font-size:20" >
< div align ="center" >< xsl:value-of select ="../TRADE" />
<!-- 如果采用xsl:if,如果股票交易量超过100000手,则加上HOT的标志 -->
< xsl:if test ="../TRADE >= 100000" > (HOT) </ xsl:if ></ div >
</ td >
</ xsl:template >
</ xsl:stylesheet >