首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSLT2.0:连续添加前面节点的值

XSLT2.0:连续添加前面节点的值
EN

Stack Overflow用户
提问于 2014-05-28 11:55:07
回答 1查看 86关注 0票数 2

让我说我有以下消息来源:

代码语言:javascript
复制
<root>
    <initialAmount>1000</initialAmount>
    <Amortization_List>
        <Amortization Index="0">10</Amortization>
        <Amortization Index="1">25</Amortization>
        <Amortization Index="2">-10</Amortization>
    </Amortization_List>
</root>

现在,我想在initialAmount中连续地添加节点Amortization,所以我的输出如下所示:

代码语言:javascript
复制
<result>
    <amount>1010</amount>
    <amount>1035</amount>
    <amount>1025</amount>
</result>

如何在XSLT2.0中做到这一点?

非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-28 11:59:19

使用

代码语言:javascript
复制
<xsl:template match="root">
  <result>
    <xsl:variable name="amount" select="initialAmount"/>
    <xsl:apply-templates select="Amortization_List/Amortization[1]">
      <xsl:with-param name="sum" select="$amount"/>
    </xsl:apply-templates>
  </result>
</xsl:template>

<xsl:template match="Amortization">
  <xsl:param name="sum"/>
  <xsl:variable name="amount" select=". + $sum"/>
  <amount><xsl:value-of select="$amount"/></amount>
  <xsl:apply-templates select="following-sibling::Amortization[1]">
    <xsl:with-param name="sum" select="$amount"/>
  </xsl:apply-templates>
</xsl:template>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23910942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档