xsl与xml的综合应用-换色换值显示

/**

Xmlxsl的综合应用,对符合条件的数据进行换值和换颜色的显示。主要的函数调用是:

<xsl:if test=”.[value()$ge$40]”>

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

</xsl:if>

<xsl:choose>

<xsl:when test=”.[value()$le$100]”>优秀</xsl:when>

<xsl:otherwise>不优秀</xsl:otherwise>

</xsl:choose>


*/

Document.xml

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

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

<document>

<resume>

<name>大象</name>

<age>88</age>

<english>59</english>

<math>68</math>

<language>99</language>

</resume>

<resume>

<name>海龟</name>

<age>999</age>

<english>99</english>

<math>88</math>

<language>99</language>

</resume>

<resume>

<name>狮子</name>

<age>20</age>

<english>12</english>

<math>22</math>

<language>55</language>

</resume>

</document>

Document.xsl

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

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

<xsl:template match="/">

<html>

<head>

<title>动物园成绩单</title>

</head>

<body>

<h3>动物园成绩单</h3>

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

</body>

</html>

</xsl:template>

<xsl:template match="document">

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

<tr><th>动物名</th><th>年龄</th><th>英语</th><th>数学</th><th>语文</th></tr>

<tr><xsl:apply-templates select="resume"/></tr>

</table>

</xsl:template>

<!--数据模板-->

<xsl:template match="resume">

<tr>

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

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

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

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

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

</tr>

</xsl:template>

<!--年龄模板-->

<xsl:template match="age">

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

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

</xsl:if>

<xsl:value-of />

</xsl:template>

<!--各科成绩模板-->

<xsl:template match="english|math|language">

<xsl:choose>

<xsl:when test=".[value()$ge$90]">优秀(90-100)</xsl:when>

<xsl:when test=".[value()$ge$70]">一般(70-90)</xsl:when>

<xsl:otherwise>不合格</xsl:otherwise>

</xsl:choose>

</xsl:template>

</xsl:stylesheet>

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念