我使用“求和函数”来计算总数,XML结构有点复杂,我在线搜索了,求和函数可以在XSLT 1.0中使用,但是我尝试了一下,它对我不起作用,我可以不知道为什么?
我的XSLT:
>
> let o = {
... "name": "Test Name",
... "age": 24
... }
undefined
>
> s = JSON.stringify(o)
'{"name":"Test Name","age":24}'
>
> s = JSON.stringify(o, undefined, 4)
'{\n "name": "Test Name",\n "age": 24\n}'
>
> console.log(s)
{
"name": "Test Name",
"age": 24
}
undefined
>
> for(k in o) {
... s = s.replace("\"" + k + "\":", k + ':')
... }
'{\n name: "Test Name",\n age: 24\n}'
>
> console.log(s)
{
name: "Test Name",
age: 24
}
undefined
>
我的XML:
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr>
<th>Quantity</th>
</tr>
<xsl:for-each select="warehouses/warehouse">
<tr>
<td><xsl:value-of select="sum(items/item/s_qty)"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
结果应为:1496
答案 0 :(得分:0)
如果要对所有s_qty求和,则必须更改
<xsl:for-each select="warehouses">
<tr>
<td><xsl:value-of select="sum(warehouse/items/item/s_qty)"/></td>
</tr>
</xsl:for-each>
请参见https://xsltfiddle.liberty-development.net/bnnZW7
上的转换您还可以使用<xsl:value-of select="sum(//s_qty)"/>