Я использую xsl для расчета совокупного итога по элементу «Базис-продукт».Наконец, выходные данные должны быть помещены в тот же xml, после "Итоговых значений" в некоторых новых элементах, таких как:
<Totals>
<Totalproduct>
<Basisproduct>110</Basisproduct>
<Cumul_Amount>1,52</CustInvoice_LineAmount>
</Totalproduct>
<Totalproduct>
<Basisproduct>198</Basisproduct>
<Cumul_Amount>294,77</CustInvoice_LineAmount>
</Totalproduct>
<Totalproduct>
<Basisproduct>992</Basisproduct>
<Cumul_Amount>163,32</CustInvoice_LineAmount>
</Totalproduct>
<Totalproduct>
<Basisproduct>993</Basisproduct>
<Cumul_Amount>193,78</CustInvoice_LineAmount>
</Totalproduct>
<Totals>
<-----I have this xml as an input.------>
<?xml version="1.0" encoding="utf-8"?>
<Report Name="SalesInvoice">
<ReportName>SalesInvoice</ReportName>
<Invoice>
<InvoicingName>Test Company</InvoicingName>
</Invoice>
<ConditionalArea>
<BodyCustInvoice>
<Basisproduct>110</Basisproduct>
<CustInvoice_LineAmount>1,52</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>198</Basisproduct>
<CustInvoice_LineAmount>20,11</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>198</Basisproduct>
<CustInvoice_LineAmount>20,22</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>992</Basisproduct>
<CustInvoice_LineAmount>3033</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>993</Basisproduct>
<CustInvoice_LineAmount>30,34</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>992</Basisproduct>
<CustInvoice_LineAmount>30,35</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>992</Basisproduct>
<CustInvoice_LineAmount>30.45</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>993</Basisproduct>
<CustInvoice_LineAmount>30,46</CustInvoice_LineAmount>
</BodyCustInvoice>
<BodyCustInvoice>
<Basisproduct>198</Basisproduct>
<CustInvoice_LineAmount>100.99</CustInvoice_LineAmount>
</BodyCustInvoice>, </ConditionalArea>
<Totals>
</Totals>
</Report>
xsl, который я использую для вычисления кумулятивной суммы "Basisproduct":
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:strip-space elements="*"/>
<xsl:decimal-format name="EU" decimal-separator="," grouping-separator="."/>
<xsl:key name="KType" match="Basisproduct" use="."/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="TotalSBasis">
<TotalSBasis>
<xsl:for-each select="/*/*/*/Basisproduct [generate-id() = generate-id(key ('KType', .)[1])]">
<xsl:variable name="currProd" select="."/>
<Totalproduct>
<xsl:copy-of select="."/>
<Cumul_Amount>
<xsl:value-of select="sum(/*/*/BodyCustInvoiceTrans [Basisproduct=$currProd]/CustInvoiceTrans_LineAmount)"/>
</Cumul_Amount>
</Totalproduct>
</xsl:for-each>
</TotalSBasis>
</xsl:template>
</xsl:stylesheet>