我正在尝试计算数值节点的总和。以下代码除了HTML之外没有返回任何内容。我知道sum()需要一个节点集。我认为我已经正确创建了变量。我在做什么错了。
谢谢。
XML示例:
谢谢。
XML示例:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<container xmlns="http://www.gtech.com/lsp/2009-09-23">
<Root>
<Incentives>
<Date>2015-03-14</Date>
<ID>507200</ID>
<ProgramName>Retailer Cash Incentive 16</ProgramName>
<Retailer>
<ID>507201</ID>
<Name>Acme #2102</Name>
<Detail>
<CashPaymentsToday>50.00</CashPaymentsToday>
<Potential>0</Potential>
</Detail>
</Retailer>
<Retailer>
<ID>507202</ID>
<Name>Acme #2103</Name>
<Detail>
<CashPaymentsToday>60.00</CashPaymentsToday>
<Potential>0</Potential>
</Detail>
</Retailer>
<Retailer>
<ID>507203</ID>
<Name>Acme #1008</Name>
<Detail>
<CashPaymentsToday>0.00</CashPaymentsToday>
<Potential>0</Potential>
</Detail>
</Retailer>
<Retailer>
<ID>507207</ID>
<Name>Acme #2228</Name>
<Detail>
<CashPaymentsToday>200.00</CashPaymentsToday>
<Potential>3</Potential>
</Detail>
</Retailer>
<Retailer>
<ID>598419</ID>
<Name>Acme NO 1071</Name>
<Detail>
<CashPaymentsToday>NONQUAL</CashPaymentsToday>
<Potential>NONQUAL</Potential>
</Detail>
</Retailer>
<Retailer>
<ID>598421</ID>
<Name>Acme NO 1072</Name>
<Detail>
<CashPaymentsToday>NONQUAL</CashPaymentsToday>
<Potential>NONQUAL</Potential>
</Detail>
</Retailer>
</Incentives>
</Root>
</container>
XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:variable name="cashPayments">
<xsl:for-each select="//Detail">
<xsl:if test="CashPaymentsToday"/>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="sum($cashPayments)"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:value-of select="sum(//gt:CashPaymentsToday[number(.) = .])"/>
。有关此测试的更完整讨论,请参见https://dev59.com/y2865IYBdhLWcg3wW9RE - bjimba