XSL/XML网页制作入门,入门到精通[13]
[入库:2005年8月18日] [更新:2007年3月25日]
<q4>10</q4>
</report>
</document>
我们采用xsl模板结合今天所学的<xsl:if>,为其编写一个xsl文档,要求季度产量小于等于20的用红色表示,文件名为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>1999年生产统计</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">
<!--此处测试产量,如小于等于20则添加一style属性color,其值为red(红色)-->
<xsl:if test=".[value()$le$20]">
<xsl:attribute name="style">color:red</xsl:attribute>
</xsl:if>
<xsl:value-of/>
</xsl:template>
</xsl:stylesheet>
<?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>1999年生产统计
</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>
本文关键:XSL/XML网页制作入门,入门到精通
本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)