如何使用XSLT 1.0获得下一个立即节点的总和

问题描述 投票:0回答:1

我有这个XML文件,其中有这些节点:

<Rows>
    <Row type="Comment">
        <Amount>0.00</Amount>
    </Row>
    <Row type="Spec">
        <Amount>10.00</Amount>
    </Row>
    <Row type="Spec">
        <Amount>10.00</Amount>
    </Row>
    <Row type="Spec">
        <Amount>10.00</Amount>
    </Row>
    <Row type="Comment">
        <Amount>0.00</Amount>
    </Row>
    <Row type="Spec">
        <Amount>20.00</Amount>
    </Row>
    <Row type="Spec">
        <Amount>10.00</Amount>
    </Row>
    <Row type="Spec">
        <Amount>20.00</Amount>
    </Row>
</Rows>

结果应为:评论:30评论:50

这些规范行将始终排在注释行之后。我需要对“注释”行之后的那些“规范”行进行求和。

我试图在XSLT 1.0中使用Preceeding and Follow函数,但无法正常工作:

<xsl:value-of select="sum(../Row[@type='Spec']/Amount][following-sibling::row[1][@type='comment']])"/>

有人可以帮忙吗?

xslt-1.0 xpath-1.0
1个回答
0
投票
XSLT 1.0
© www.soinside.com 2019 - 2024. All rights reserved.