Hello,
I have the following XML:
<nodeList >
<node group="chassis" instanceName="7604-RSP720C
-P" unitPrice1="60" discount="0.0" quantity="1.0">
<node instanceName="2700W-DC" unitPrice1="100" discount="0.00" quantity="2.0000" />
<node instanceName="RSP720-3C-GE
" unitPrice1="100" discount="0.00" quantity="3.0000" />
</node>
<node group="chassis" instanceName="222222222" unitPrice1="100" discount="30.00" /uantity="4.000">
<node instanceName="1C" unitPrice1="N/A" discount="0.00" quantity="5.0000" />
<node instanceName="2E" unitPrice1="N/A" discount="0.00" quantity="5.0000" />
</node>
<node group="chassis" instanceName="333333333" unitPrice1="N/A" discount="0.00" quantity="6.0000">
<node instanceName="1C" unitPrice1="N/A" discount="0.00" quantity="7.0000" />
<node instanceName="2E" unitPrice1="N/A" discount="0.00" quantity="8.0000" />
</node>
</nodeList>
what i would like to do is to summerize the total price of each group and the total price of all the groups (all the nodes).
I managed to count the sum of each group by using the following code:
<xsl:template match="NfxML/body/nodeList
">
<xsl:for-each select="node[count(.|key('
contacts-b
y-chasi', @instanceName)[1]) = 1]">
<xsl:variable name="GroupName" select="@instanceName"/>
<br /><xsl:value-of select="$GroupName" />:
<xsl:variable name="TotalSum">
<xsl:call-template name="calculator">
<xsl:with-param name="curSum">0</xsl:with-
param>
<xsl:with-param name="counter"><xsl:value-
of select="count(descendant-o
r-self::*)
"/></xsl:w
ith-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$TotalSum"/>
<br />
</xsl:for-each>
</xsl:template>
<xsl:template name="calculator">
<xsl:param name="curSum"/>
<xsl:param name="counter"/>
<xsl:variable name="qty" select="number(descendant-
or-self::*
[number($c
ounter)]/@
quantity)"
/>
<xsl:variable name="cost" select="number(descendant-
or-self::*
[number($c
ounter)]/@
unitPrice1
)"/>
<xsl:variable name="discount" select="number(descendant-
or-self::*
[number($c
ounter)]/@
discount)"
/>
<xsl:variable name="sum" select="number($cost*(100-
$discount)
div 100 * $qty)"/>
<xsl:variable name="CycleSum">
<xsl:choose>
<xsl:when test="string(number($sum))
= 'NaN'">
<xsl:value-of select="number($curSum)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number($curSum + $sum)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="number($counter - 1) > 0 ">
<xsl:call-template name="calculator">
<xsl:with-param name="curSum"><xsl:value-o
f select="$CycleSum"/></xsl:
with-param
>
<xsl:with-param name="counter">
<xsl:value-of select="number($counter - 1)"/>
</xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$CycleSum"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Who can i get the total sum in the most efficient way?
the output I would like to get is:
7604-RSP720C-P: 560
222222222: 280
333333333: 0
Total: 840