这是我的xml:
<?xml version = "1.0" encoding = "ISO-8859-1"?>
<List>
<Customer>
<client name="Jean Charles" />
<transaction amount="500" />
<question> What is the latest brand </question>
<transaction amount="1200" />
</Customer>
<Customer>
<client name="Philippe" />
<transaction amount="600" />
<transaction amount="800" />
<question> Where can I find the 2002 model </question>
<transaction amount="2000" />
</Customer>
</List>
和XSLT:
<?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="/">
<html>
<body>
<h2>Customer transaction</h2>
<table border="1">
<xsl:for-each select="List/Customer">
<tr>
<td><xsl:value-of select="client/@name"/></td>
<xsl:for-each select="transaction">
<td><xsl:value-of select="@amount"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
但我需要每个客户交易金额的总和。第一个客户500 + 1200 = 1700的示例。
任何人都可以帮忙解决这个问题。
答案 0 :(得分:0)
您可以使用the sum
function:
<xsl:for-each select="List/Customer">
<tr>
<td><xsl:value-of select="client/@name"/></td>
<td><xsl:value-of select="sum(transaction/@amount)" /></td>
</tr>
</xsl:for-each>