Thanks Mukul,
This solution worked perfectly to my problem.
Regards,
Vidya
-----Original Message-----
From: Mukul Gandhi [mailto:mukul_gandhi(_at_)yahoo(_dot_)com]
Sent: Thursday, May 06, 2004 10:10 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Compute sum of a computed node list
Hi Vidya,
Below is the modified stylesheet. It also uses the
nodeset function.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
<xsl:decimal-format name="MyFormat"
decimal-separator="." grouping-separator=","/>
<xsl:template match="/">
<xsl:apply-templates select="abcd_list"/>
</xsl:template>
<xsl:template match="abcd_list">
<abcd_list>
<xsl:for-each select="abcd">
<abcd>
<xsl:variable name="state_local_salary"
select="state_local_salary"/>
<xsl:variable name="quarterly_sessions"
select="quarterly_sessions"/>
<xsl:variable name="non_medicaid_sessions"
select="non_medicaid_sessions"/>
<xsl:variable name="var_state_local_match"
select="$state_local_salary * ($quarterly_sessions div
($non_medicaid_sessions))"/>
<state_local_match>
<xsl:value-of
select="format-number($var_state_local_match,'###,###.##','MyFormat')"/>
</state_local_match>
</abcd>
</xsl:for-each>
<xsl:variable name="rtf">
<xsl:for-each select="abcd">
<abcd>
<xsl:if test="state_local_salary[not(@null)]">
<xsl:variable name="state_local_salary"
select="state_local_salary"/>
<xsl:variable name="quarterly_sessions"
select="quarterly_sessions"/>
<xsl:variable name="non_medicaid_sessions"
select="non_medicaid_sessions"/>
<xsl:variable name="var_state_local_match"
select="$state_local_salary * ($quarterly_sessions div
($non_medicaid_sessions))"/>
<state_local_match>
<xsl:value-of
select="$var_state_local_match"/>
</state_local_match>
</xsl:if>
</abcd>
</xsl:for-each>
</xsl:variable>
<state_local_match_total>
<xsl:value-of
select="format-number(sum(xalan:nodeset($rtf)/abcd/state_local_match),
'###,###.##','MyFormat')"/>
</state_local_match_total>
</abcd_list>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul