【发布时间】:2015-03-18 19:23:27
【问题描述】:
我正在尝试使用 XPath 获得平均值,但我得到的是 NaN 作为输出。
这是我的 XML 文件:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet href="class.xsl" type="text/xsl" ?>
<university>
<student><sname>Charlie Parker</name>
<course sigle="INF8430" note="69" />
<course sigle="INF1030" note="65" />
<course sigle="INF1230" note="73" /></student>
<student><name>Miles Davis</name>
<course sigle="INF8430" note="65" />
<course sigle="INF1030" note="77" />
<course sigle="INF1230" note="83" /></student>
<student><name>John Coltrane</name>
<course sigle="INF9430" note="24" />
<course sigle="INF1030" note="64" />
<course sigle="INF1230" note="56" /></student>
<student><name>Charles Mingus</name>
<course sigle="INF8430" note="34" />
<course sigle="INF1230" note="89" /></student>
</university>
现在是 XSL 文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="university">
<html>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Average</th>
</tr>
<xsl:for-each select="student">
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="sum(.//student/@note) div count(.// student/@note)"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我遇到的另一个问题是当我尝试按表中的升序对姓氏进行排序时。它只是行不通。
我尝试添加这段代码但没有成功:
<xsl:apply-templates select="student" >
<xsl:sort select="substring-after(name,' ')" order="ascending"/>
</xsl:apply-templates>
你们能帮我解决这个问题吗? 非常感谢!
【问题讨论】: