对xml中符合条件的值换值显示
/** 对于xml中某一区域的值进行评级显示。
*/
Grade.xml
<?xml version="1.0" encoding="gb2312"?> <?xml-stylesheet type="text/xsl" href="grade.xsl"?> <document> <grade> <name>大胖</name> <english>80</english> <math>90</math> <chymest>90</chymest> </grade> <grade> <name>小花</name> <english>98</english> <math>60</math> <chymest>85</chymest> </grade> </document>
Grade.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> <xsl:apply-templates select="document"/> </body> </html> </xsl:template>
<xsl:template match="document"> <table border="1" cellspacing="0"> <th>姓名</th><th>英语</th><th>数学</th><th>化学</th> <xsl:apply-templates select="grade"/> </table> </xsl:template>
<xsl:template match="grade"> <tr> <td><xsl:apply-templates select="name"/></td> <td><xsl:apply-templates select="english"/></td> <td><xsl:apply-templates select="math"/></td> <td><xsl:apply-templates select="chymest"/></td> </tr> </xsl:template>
<xsl:template match="name"> <xsl:value-of /> </xsl:template>
<xsl:template match="english|math|chymest"> <xsl:choose> <xsl:when test=".[value()$ge$85]">优秀</xsl:when> <xsl:when test=".[value()$ge$70]">一般</xsl:when> <xsl:otherwise>不及格</xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |