Xml XSLT2.0:连续添加前面节点的值
假设我有以下来源:Xml XSLT2.0:连续添加前面节点的值,xml,add,xslt-2.0,Xml,Add,Xslt 2.0,假设我有以下来源: <root> <initialAmount>1000</initialAmount> <Amortization_List> <Amortization Index="0">10</Amortization> <Amortization Index="1">25</Amortization> <Amortizat
<root>
<initialAmount>1000</initialAmount>
<Amortization_List>
<Amortization Index="0">10</Amortization>
<Amortization Index="1">25</Amortization>
<Amortization Index="2">-10</Amortization>
</Amortization_List>
</root>
如何在XSLT2.0中实现这一点
非常感谢 使用
<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>
谢谢您的回答。但这并不完全是我所需要的。您的解决方案将每个节点的值添加到初始值中,但我希望将其添加到上一个值中。@user2986852,我已更改代码以解决您的问题。谢谢,它可以工作!我无法理解它是如何做到的,但我会努力弄清楚。再次感谢。请注意,其中有一个小错误:应该是,但我无权编辑您的帖子。很抱歉,结束标记不正确,现已更正。至于它是如何工作的,我们从第一个摊销
开始,然后使用后面的同级轴
逐步计算您要查找的值,并将当前值作为参数传递。
<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>