0

我需要添加多个值​​,具体取决于每个项目的内容。例如。

<links>
<test element="32"/>
<test element="17"/>
<test element="13"/>
<test element="11"/>
<test element="9"/>
<test element="8"/>
<test element="7"/>
<test element="7"/>
</links>

元素总数:8,每个元素的值之和:104,a显示的值为this(104)。

  <xsl:template match="//x:span[@class='ws-filter-count']">
    <xsl:variable name="countProduct" select="normalize-space(translate(text(), '()', ''))" />
    <xsl:variable name="sum" select="number(0)"/>
    <test element="{$countProduct}" />
  </xsl:template>

这个总和:

这只能通过调用模板来完成吗?,递归的,对吗?谢谢。

4

1 回答 1

1

如果我正确理解了您想要实现的目标:

样式表

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" version="1.0"/>

  <xsl:template match="links">
    <xsl:value-of select="sum(test/@element)"/>
  </xsl:template>
</xsl:stylesheet>

输入

<links>
  <test element="32"/>
  <test element="17"/>
  <test element="13"/>
  <test element="11"/>
  <test element="9"/>
  <test element="8"/>
  <test element="7"/>
  <test element="7"/>
</links>

输出

104
于 2013-04-05T11:30:27.217 回答