我有一个xml文件,我使用xsl转换为html
<?xml version="1.0"?>
<list>
<student>
<name>Tom</name>
<class>1</class>
</student>
<student>
<name>Jerry</name>
<class>2</class>
</student>
</list>
这是我的XSL文件,我在模板Money中显示信息"Name"one_answers"Class"并显示"Money"与条件
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<title>TomJerryXSL.xsl</title>
</head>
<body>
<table border="1" >
<tr>
<td>Name</td>
<td>Class</td>
<td>Money</td>
</tr>
<xsl:for-each select="/list/student">
<tr>
<td><xsl:value-of select="./name"/></td>
<td><xsl:value-of select="./class"/></td>
<td>
<xsl:call-template name="money">
<xsl:with-param name="class">
<xsl:value-of select="./class"/>
</xsl:with-param>
</xsl:call-template>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template name="money">
<xsl:param name="class"/>
<xsl:choose>
<xsl:when test="$class=1">
<xsl:value-of select="100"/>
</xsl:when>
<xsl:when test="$class=2">
<xsl:value-of select="200"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
i want show Total 300
Name Class Money
Tom 1 100
Jerry 2 200
如何总结金钱并在html中显示对不起,因为我的英语不好
试试这样写:
<xsl:value-of select="100*count(/list/student/class[.='1']) + 200*count(/list/student/class[.='2'])"/>