XSL 条件处理

两种:

1.xsl:if
None.gif < xsl:if  test ="逻辑表达式" >
None.gif
</ xsl:if >

2.xsl:choose
None.gif < xsl:choose >
None.gif    
< xsl:when  test ="逻辑表达式" >
None.gif    
</ xsl:when >
None.gif    
< xsl:when  test ="逻辑表达式" >
None.gif    
</ xsl:when >
None.gif    
< xsl:otherwise >
None.gif    
</ xsl:otherwise >
None.gif
</ xsl:choose >

例子:

ex29.xml

None.gif <? xml version="1.0" encoding="gb2312" ?>
None.gif
<? xml-stylesheet type="text/xsl" href="ex29.xsl" ?>
None.gif
< DOCUMENT >
None.gif    
< STOCK >
None.gif        
< NUMBER > 000868 </ NUMBER >
None.gif        
< NAME > 安凯客车 </ NAME >
None.gif        
< START > 7.10 </ START >
None.gif        
< END > 7.78 </ END >
None.gif        
< TRADE > 69295 </ TRADE >
None.gif    
</ STOCK >
None.gif    
< STOCK >
None.gif        
< NUMBER > 000720 </ NUMBER >
None.gif        
< NAME > 鲁能泰山 </ NAME >
None.gif        
< START > 19.00 </ START >
None.gif        
< END > 19.91 </ END >
None.gif        
< TRADE > 34445 </ TRADE >
None.gif    
</ STOCK >
None.gif    
< STOCK >
None.gif        
< NUMBER > 000099 </ NUMBER >
None.gif        
< NAME > 中信海直 </ NAME >
None.gif        
< START > 9.95 </ START >
None.gif        
< END > 9.83 </ END >
None.gif        
< TRADE > 120300 </ TRADE >
None.gif    
</ STOCK >
None.gif    
< STOCK >
None.gif        
< NUMBER > 000926 </ NUMBER >
None.gif        
< NAME > 福星科技 </ NAME >
None.gif        
< START > 12.14 </ START >
None.gif        
< END > 12.23 </ END >
None.gif        
< TRADE > 25678 </ TRADE >
None.gif    
</ STOCK >
None.gif
</ DOCUMENT >

ex29.xsl
None.gif <? xml version="1.0" encoding="gb2312" ?>
None.gif
< xsl:stylesheet  version ="1.0"  xmlns:xsl ="http://www.w3.org/1999/XSL/Transform" >
None.gif
< xsl:template  match ="/" >
None.gif    
< html >
None.gif    
< head >
None.gif        
< title ></ title >
None.gif    
</ head >
None.gif    
< body >
None.gif    
< align ="center" >< font  size ="7" > 股票价格表 </ font ></ p >
None.gif    
< table  width ="90%" >
None.gif        
< tr >
None.gif            
< td  width ="18%" >< div  align ="center" > 编号 </ div ></ td >
None.gif            
< td  width ="18%" >< div  align ="center" > 简称 </ div ></ td >
None.gif            
< td  width ="15%" >< div  align ="center" > 开盘价 </ div ></ td >
None.gif            
< td  width ="15%" >< div  align ="center" > 收盘价 </ div ></ td >
None.gif            
< td  width ="24%" >< div  align ="center" > 成交量 </ div ></ td >
None.gif        
</ tr >
None.gif        
< xsl:for-each  select ="//STOCK" >
None.gif            
<!--  使用xsl:choose对每个股票进行相关测试  -->
None.gif            
< xsl:choose >
None.gif                
<!--  股票价格在下跌  -->
None.gif                
< xsl:when  test ="(END - START) div START &lt; 0" >
None.gif                    
< tr  bgcolor ="#C0C0C0" >< xsl:apply-templates  select ="NUMBER" /></ tr >
None.gif                
</ xsl:when >
None.gif                
<!--  股票涨幅在5%以内  -->
None.gif                
< xsl:when  test ="(END - START) div START >= 0 and (END - START) div START &lt; 0.05" >
None.gif                    
< tr  bgcolor ="#00FF00" >< xsl:apply-templates  select ="NUMBER" /></ tr >
None.gif                
</ xsl:when >
None.gif                
<!--  股票涨幅在5%-10%之间  -->
None.gif                
< xsl:when  test ="(END - START) div START >=0.05 and (END - START) div START &lt; 0.10" >
None.gif                    
< tr  bgcolor ="#0000FF" >< xsl:apply-templates  select ="NUMBER" /></ tr >
None.gif                
</ xsl:when >
None.gif                
<!--  默认情况,股票涨幅在10%以上   -->
None.gif                
< xsl:otherwise >
None.gif                    
< tr  bgcolor ="#FFFF00" >< xsl:apply-templates  select ="NUMBER" /></ tr >
None.gif                
</ xsl:otherwise >
None.gif            
</ xsl:choose >
None.gif        
</ xsl:for-each >
None.gif    
</ table >
None.gif    
< br />< br />
None.gif    
< align ="left" >< font  size ="4" > 灰色-股票正在下跌 </ font ></ p >
None.gif    
< align ="left" >< font  size ="4" > 绿色-股票涨幅在5%以内 </ font ></ p >
None.gif    
< align ="left" >< font  size ="4" > 蓝色-股票涨幅在5%到10%之间 </ font ></ p >
None.gif    
< align ="left" >< font  size ="4" > 黄色-股票涨幅在10%以上 </ font ></ p >
None.gif    
< align ="left" >< font  size ="4" > HOT标记-交易量超过100000手的股票 </ font ></ p >
None.gif    
</ body >
None.gif    
</ html >
None.gif
</ xsl:template >
None.gif
< xsl:template  match ="NUMBER" >
None.gif    
< td  style ="font-style:楷体_gb2312; font-size:20" >
None.gif        
< div  align ="center" >< xsl:value-of  select ="." /></ div >
None.gif    
</ td >
None.gif    
< td  style ="font-style:楷体_gb2312; font-size:20" >
None.gif        
< div  align ="center" >< xsl:value-of  select ="../NAME" /></ div >
None.gif    
</ td >
None.gif    
< td  style ="font-style:楷体_gb2312; font-size:20" >
None.gif        
< div  align ="center" >< xsl:value-of  select ="../START" /></ div >
None.gif    
</ td >
None.gif    
< td  style ="font-style:楷体_gb2312; font-size:20" >
None.gif        
< div  align ="center" >< xsl:value-of  select ="../END" /></ div >
None.gif    
</ td >
None.gif    
< td  style ="font-style:楷体_gb2312; font-size:20" >
None.gif        
< div  align ="center" >< xsl:value-of  select ="../TRADE" />
None.gif        
<!--  如果采用xsl:if,如果股票交易量超过100000手,则加上HOT的标志  -->
None.gif        
< xsl:if  test ="../TRADE >= 100000" > (HOT) </ xsl:if ></ div >
None.gif    
</ td >
None.gif
</ xsl:template >
None.gif
</ xsl:stylesheet >

转载于:https://www.cnblogs.com/wddavid/archive/2005/07/21/197532.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值