XSLT1.0高级计算

XSLT1.0高级计算,xslt,xslt-1.0,Xslt,Xslt 1.0,我已经在这上面把头撞到墙上有一段时间了。我们的应用程序处理来自另一个系统的复杂结构XML发票。发票包含包含各种计数的信息行。这些计数可能包含值,也可能不包含值。有一个总的文件费用。我们需要算出单位费用。公式是总成本除以总计数 我一直在研究其他人提供的有关XSLT1.0中求和的示例。我可以使用xsl:call模板获得计数的总和,但我不知道如何将结果应用于计算单价 示例XML <Document> <Row> <Count1>

我已经在这上面把头撞到墙上有一段时间了。我们的应用程序处理来自另一个系统的复杂结构XML发票。发票包含包含各种计数的信息行。这些计数可能包含值,也可能不包含值。有一个总的文件费用。我们需要算出单位费用。公式是总成本除以总计数

我一直在研究其他人提供的有关XSLT1.0中求和的示例。我可以使用xsl:call模板获得计数的总和,但我不知道如何将结果应用于计算单价

示例XML

<Document>
    <Row>
        <Count1>
            <Value>10</Value>
        </Count1>
        <Count2>
            <Value/>
        </Count2>
    </Row>
    <Row>
        <Count1>
            <Value>5</Value>
        </Count1>
        <Count2>
            <Value>6</Value>
        </Count2>
    </Row>
    <Row>
        <Count1>
            <Value>2</Value>
        </Count1>
        <Count2>
            <Value>3</Value>
        </Count2>
    </Row>
    <Charge>
        <Value>260</Value>
    </Charge>
</Document>

10
5.
6.
2.
3.
260
如果我能看到如何获得下面的XML输出,它可能会告诉我我需要什么

<Document>
    <Row>
        <Total>10</Total>
        <UnitPrice>10</UnitPrice>
    </Row>
    <Row>
        <Total>11</Total>
        <UnitPrice>10</UnitPrice>
    </Row>
    <Row>
        <Total>15</Total>
        <UnitPrice>10</UnitPrice>
    </Row>
</Document>

10
10
11
10
15
10

非常感谢您提前

您只需调用
sum()
所需的值,如下所示:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/Document">
    <Document>
        <xsl:apply-templates select="Row"/>
    </Document>
  </xsl:template>
  <xsl:template match="Row">
    <Row>
        <Total>
            <xsl:value-of select="sum(./*[Value&gt;0]/Value)"/>
        </Total>
        <UnitPrice>10</UnitPrice>
    </Row>
  </xsl:template>
</xsl:stylesheet>

10
这将提供以下输出:

<Document>
    <Row>
        <Total>10</Total>
        <UnitPrice>10</UnitPrice>
    </Row>
    <Row>
        <Total>11</Total>
        <UnitPrice>10</UnitPrice>
    </Row>
    <Row>
        <Total>5</Total>
        <UnitPrice>10</UnitPrice>
    </Row>
</Document>

10
10
11
10
5.
10

很乐意为您提供帮助,但您需要发布您尝试过的XSL,并明确目标。