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

RE: Calculating Sum in XSLT 1.0

Subject: RE: Calculating Sum in XSLT 1.0
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Wed, 22 Dec 2004 20:37:04 -0800 (PST)
function not in namespace
There seems to be no need to use nodeset function. You
can simply write the XSL as below -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
<xsl:output method="html" indent="yes" />
  
<xsl:template match="/root">  
  <xsl:apply-templates select="currentnode" />
</xsl:template>
  
<xsl:template match="currentnode">
  <p><xsl:value-of
select="sum(preceding-sibling::sibling/@value)" /></p>
</xsl:template>
  
</xsl:stylesheet>

When the above XSL is applied to XML -
<?xml version="1.0" encoding="UTF-8"?>
<root>
 <sibling value="5"/>
 <sibling value="7"/>
 <sibling value="9"/>
 <sibling value="13"/>
 <currentnode>some text</currentnode>
</root>

the o/p recieved is -
<p>34</p>

Regards,
Mukul

--- Abhijit Junnare <mavlaabhi@xxxxxxxxx> wrote:

> will this work with xalan? because i tried to use
> something like this and it gave me an error. 
> 
> also i tried using this
> <xsl:template match="currentnode"
> ...
> ...
> 
> <xsl:variable name="Total">
> 	<xsl:for-each
> select="preceding-sibling::sibling[@value]">
> 	    <SubTotal>
> 	      <xsl:value-of select="(@value)"/>
> 	    </SubTotal>
> 	  </xsl:for-each>
> </xsl:variable>
> 
> <p>
>   <xsl:value-of
> select="sum(xalan:nodeset($Total)/SubTotal)"/>
> <br/>
> </p>
> 
> </xsl:template>
> 
> and it gives me an error 
> 
> "function not in namespaceError in Xpath expression,
> function not in namespace"
> 
> Please let me know.
> Thanks,
> Abhi
> 
> 
> 
> --- Michael Kay <mike@xxxxxxxxxxxx> wrote:
> 
> > sum(preceding-sibling::sibling/@value)
> > 
> > Michael Kay
> > http://www.saxonica.com/ 
> > 
> > > -----Original Message-----
> > > From: Abhijit Junnare
> [mailto:mavlaabhi@xxxxxxxxx]
> > 
> > > Sent: 22 December 2004 17:09
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject:  Calculating Sum in XSLT 1.0
> > > 
> > > I am trying to generate a sum of attribute
> values
> > of
> > > sibling nodes via XSLT 1.0
> > > 
> > > My XML looks like this
> > > 
> > > <sibling value="5"/>
> > > <sibling value="7">
> > > <sibling value="9">
> > > <sibling value="13">
> > > <currentnode>some text</currentnode>
> > > 
> > > When I am processing the template for
> currentnode
> > I
> > > want to calculate the sum of the "value"
> attribute
> > of
> > > all its previous sibling nodes i.e. I want to
> find
> > the
> > > sum of 5,7,9 and 13. The names of the sibling
> node
> > and
> > > current node are different. 
> > > I know there isn't a direction function to do
> > this. If
> > > anyone has written template or come accross the
> > > problem then please let me know how did you
> solve
> > it. 
> > > Thank you for your help and Merry Christmas.
> > > Abhi
> > > 
> > > 
> > > 
> > > 		
> > > __________________________________ 
> > > Do you Yahoo!? 
> > > Read only the mail you want - Yahoo! Mail
> > SpamGuard. 
> > > http://promotions.yahoo.com/new_mail 
> > 
> > 
> 
> 
> 
> 		
> __________________________________ 
> Do you Yahoo!? 
> Yahoo! Mail - Easier than ever with enhanced search.
> Learn more.
> http://info.mail.yahoo.com/mail_250
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Easier than ever with enhanced search. Learn more.
http://info.mail.yahoo.com/mail_250

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.