对xml中符合条件的值改变样式显示

15 篇文章 0 订阅

/**

1.测试模式相对于匹配模式来讲它只是多了一个<xsl:if test=”.[value()$le$20]”><xsl:attribute name=”style”>color:red</xsl:attribute></xsl:if>这样的条件,以此来改变符合某些条件的值的属性。本质上它与匹配模式是一样的。

对xml中符合条件的值改变样式显示 - lishirong - The CTO of LiShirong
 

*/

Report.xml

<?xml version="1.0" encoding="gb2312"?>

<?xml-stylesheet type="text/xsl" href="report.xsl"?>

<document>

       <report>

              <class>甲班</class>

              <q1>50</q1>

              <q2>70</q2>

              <q3>30</q3>

              <q4>10</q4>

       </report>

       <report>

              <class>乙班</class>

              <q1>10</q1>

              <q2>20</q2>

              <q3>30</q3>

              <q4>40</q4>

       </report>

       <report>

              <class>丙班</class>

              <q1>70</q1>

              <q2>40</q2>

              <q3>20</q3>

              <q4>10</q4>

       </report>

</document>

 

 

Report.xsl

 

 

<?xml version="1.0" encoding="gb2312"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

       <xsl:template match="/">

              <html>

                     <head><title>1999年生产统计</title></head>

                     <body>

                            <xsl:apply-templates select="document"/>

                     </body>        

              </html>

       </xsl:template>

      

       <xsl:template match="document">

                     <h3>2000年生产统计</h3>

                     <table border="1" cellspacing="0">

                            <th>班组</th>

                            <th>一季度</th>

                            <th>二季度</th>

                            <th>三季度</th>

                            <th>四季度</th>

                            <xsl:apply-templates select="report"/>

                     </table>

       </xsl:template>

      

       <xsl:template match="report">

              <tr>

                     <td><xsl:value-of select="class"/></td>

                     <td><xsl:apply-templates select="q1"/></td>

                     <td><xsl:apply-templates select="q2"/></td>

                     <td><xsl:apply-templates select="q3"/></td>

                     <td><xsl:apply-templates select="q4"/></td>

              </tr>

       </xsl:template>

       <!--测试数据是否符合过滤条件,如果符合则将其红色显示-->

       <xsl:template match="q1|q2|q3|q4">

              <xsl:if test=".[value()$le$20]">

                     <xsl:attribute name="style">color:red</xsl:attribute>

              </xsl:if>

              <xsl:value-of />

       </xsl:template>

</xsl:stylesheet>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值