关于XML中XSL的问题
有xml文档如下:
<?xml version="1.0" encoding="gb2312"?>
<studentlist>
<student id="s001">
<name>alex</name>
<gender>male</gender>
<birthday>1978.2</birthday>
<score>92</score>
<skill>java</skill>
</student>
<student id="s002">
<name>amy</name>
<gender>female</gender>
<birthday>1979.3</birthday>
<score>98</score>
<skill>dotNet Framework</skill>
</student>
<student id="s003">
<name>joyce</name>
<gender>female</gender>
<birthday>1977.6</birthday>
<score>83</score>
<skill>Database Development</skill>
</student>
</studentlist>
要求写出一个xsl文件
提示:表格中的总分,总人数,平均分都是xsl文档自动计算出来;评价的等级根据条件自动判断。(参考: 60分以下不及格、60分以上属于及格、70分以上属于中等、80分以上属于良好、90分以上优秀)
?1.分析xml文档
2.写出xsl文档格式化xml文档
[解决办法]
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head><title>4-4</title></head>
<body>
<table border="1" width="100%">
<tr><th>编号</th><th>姓名</th><th>性别</th><th>生日</th><th>成绩</th><th>评价</th></tr>
<xsl:for-each select="studentlist/student">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="gender"/></td>
<td><xsl:value-of select="birthday"/></td>
<td><xsl:value-of select="score"/></td>
<xsl:choose>
<xsl:when test="score > 90">
<td>优秀</td>
</xsl:when>
<xsl:when test="score > 80">
<td>良好</td>
</xsl:when>
<xsl:when test="score > 70">
<td>中等</td>
</xsl:when>
<xsl:when test="score > 60">
<td>及格</td>
</xsl:when>
<xsl:otherwise>
<td>不及格</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
<tr>
<th colspan="4" align="center">总分</th><th><xsl:value-of select="sum(//score)"/></th>
</tr>
<tr>
<th colspan="4" align="center">总人数</th><th><xsl:value-of select="count(//student)"/></th>
</tr>
<tr>
<th colspan="4" align="center">平均分</th><th><xsl:value-of select="sum(//score) div count(//student)"/></th>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>