对xml中符合条件的值改变样式显示
/** 1.测试模式相对于匹配模式来讲它只是多了一个<xsl:if test=”.[value()$le$20]”><xsl:attribute name=”style”>color:red</xsl:attribute></xsl:if>这样的条件,以此来改变符合某些条件的值的属性。本质上它与匹配模式是一样的。
*/ 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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |