2013-08-31 24 views
0

这里是我的xml:如何让另外在动态XSLT

<?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

您可以使用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> 
+0

非常感谢它的工作:) – ManyamSagar