对xml中符合条件的值换值显示

前端之家收集整理的这篇文章主要介绍了对xml中符合条件的值换值显示前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

/**

对于xml中某一区域的值进行评级显示

*/

Grade.xml

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

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

<document>

<grade>

@H_404_55@ <name>大胖</name>

@H_404_55@ <english>80</english>

@H_404_55@ <math>90</math>

@H_404_55@ <chymest>90</chymest>

</grade>

<grade>

@H_404_55@ <name>小花</name>

@H_404_55@ <english>98</english>

@H_404_55@ <math>60</math>

@H_404_55@ <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="/">

@H_404_55@ <html>

<head>

<title>成绩单</title>

</head>

<body>

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

</body>

@H_404_55@ </html>

</xsl:template>

<xsl:template match="document">

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

<th>姓名</th><th>英语</th><th>数学</th><th>化学</th>

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

@H_404_55@ </table>

</xsl:template>

<xsl:template match="grade">

@H_404_55@ <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>

@H_404_55@ </tr>

</xsl:template>

<xsl:template match="name">

@H_404_55@ <xsl:value-of />

</xsl:template>

@H_404_55@

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

@H_404_55@ <xsl:choose>

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

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

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

@H_404_55@ </xsl:choose>

</xsl:template>

</xsl:stylesheet>

猜你在找的XML相关文章