我需要修改我的XSLT代碼以獲得不同的輸出結果。我需要輸出一個包含學號和平均數的表格。爲不同的輸出修改XSLT XPATH代碼
這裏是我的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>
這裏是我的XSLT代碼至今:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/university">
<html>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Average</th>
</tr>
<xsl:for-each select="student">
<xsl:sort select="substring-after(name, ' ')"/>
<tr>
<td><xsl:value-of select="name" /></td>
<td><xsl:value-of select="sum(course/@note) div count(course)"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
這裏的輸出應該是什麼樣子:
非常感謝您的幫助!
「INF9430」課程中只有一個人註冊 - 爲什麼平均「39.0」?另外,你應該照顧你之前的一些問題。要麼接受或以其他方式對給出的[這裏](http://stackoverflow.com/a/28753643/1987598)和[這裏](http://stackoverflow.com/a/28998433/1987598)給出的答案作出反應。 – 2015-04-01 14:17:06