[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Compute sum of a computed node list

Subject: RE: Compute sum of a computed node list
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Thu, 6 May 2004 08:10:04 -0700 (PDT)
xsl variable sum
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


> THE XSLT FILE
> ===================    
> 
> <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>
>             <state_local_match_total>
>             <xsl:value-of
>
select="format-number(sum(rehab/state_local_match[number(.)!='-']),'###,###.
> ##','MyFormat')"/>
>         </state_local_match_total>
>         </abcd_list>
>     </xsl:template>
> 
> SAMPLE FILE
> ===============
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <abcd_list>
>     <abcd num="1">        
>        
> <state_local_salary>1600.0</state_local_salary>
>         <quarterly_sessions>12</quarterly_sessions>
>        
> <non_medicaid_sessions>2</non_medicaid_sessions>    
>    
>     </abcd>
>     <abcd num="2">        
>         <state_local_salary null="true"/>
>         <quarterly_sessions>9</quarterly_sessions>
>        
> <non_medicaid_sessions>2</non_medicaid_sessions>    
>    
>     </abcd>
>     <abcd num="3">        
>        
> <state_local_salary>1700.0</state_local_salary>
>         <quarterly_sessions>7</quarterly_sessions>
>        
> <non_medicaid_sessions>2</non_medicaid_sessions>    
>   
>     </abcd>
>     <abcd num="4">       
>        
> <state_local_salary>1700.0</state_local_salary>
>         <quarterly_sessions>5</quarterly_sessions>
>        
> <non_medicaid_sessions>2</non_medicaid_sessions>    
>    
>     </abcd>
> </abcd_list>
> 



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.