RE: [xsl] xsl numeric calculations-NP

Subject: RE: [xsl] xsl numeric calculations-NP
From: "NILESH PATEL" <jayganesh786@xxxxxxxxxxx>
Date: Fri, 02 Aug 2002 10:48:19 +0000

Marvellous, This works, Only change I had to as you said was to use xalan specific nodeset function which is,:


<xsl:value-of
select="sum(xalan:nodeset($fruits-rtf)/fruit/@totalcost)"/>

Thanks very much for your effort.


Nilesh

From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: RE: [xsl] xsl numeric calculations-NP
Date: Fri, 2 Aug 2002 10:49:21 +0100


The easiest solution here I think is to do the first operation (quantity * unit_price) in a variable and then sum() the values of that using node-set()

<xsl:variable name="fruits-rtf">
  <xsl:for-each select="//fruits/*">
    <fruit name="{name()}" totalcost="{@quantity * @unit_price}"/>
  </xsl:for-each>
</xsl:variable>

This variable will hold a result-tree-fragment of <fruit> elements with
an attribute @totalcost which holds the result of quantity * unit_price

You can then calculate the sum() of the @totalcost by using the
node-set() extension function of your favourite processor:

<xsl:value-of
select="sum(exsl:node-set($fruits-rtf)/fruit/@totalcost)"/>


cheers andrew



> -----Original Message-----
> From: NILESH PATEL [mailto:jayganesh786@xxxxxxxxxxx]
> Sent: 02 August 2002 08:20
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] xsl numeric calculations-NP
>
>
>
>
> Dear Friends,
>
> I am trying to achoeve simple calcuateion from xsl. I do not
> know the way
> out of this. Please help. Here is the code.
>
> XML:
> ======
> <Shopping>
> 	<fruits>
> 		<apple quantity="10" unit_price="1"></apple>
> 		<orange quantity="20" unit_price="5"></orange>
> 		<banana quantity="30" unit_price="5"></banana>
> 		<grapes quantity="40" unit_price="5"></grapes>
> 	</fruits>
> 	<vegs>
> 		<onion quantity="10" unit_price="5"></onion>
> 		<carrot quantity="5" unit_price="10"></carrot>
> 		<chiili quantity="20" unit_price="5"></chilli>
> 		<tomato quantity="10" unit_price="5"></tomato>
> 		<potato quantity="20" unit_price="5"></potato>
> 	</vegs>
> </shopping>
>
> XSL:
> ======
> //suggest xsl template here, because I tried using sum() and
> numbers and so
> on but could not work the way around it. I could do individual
> multiplication using <xsl:for-each select="//fruits/*">. but
> did not achieve
> results.SO I BEG TO THE COMMUNITY, PLEASE HELP ME NOW.
>
>
> Required Result:
> =================
> FRUITS:  (10*1) + (20*5) + (30*5) + (40*5) = 460
> VEGS  :  (10*5) + (5*10) + (20*5) + (10*5) + (20*5) = 350
>
>
>
> Basically, I want to multiply "quantity" and "unit_price"
> first then add the
> multiplication-result.May be using javascript or xsl built in
> functions,
> please suggest.
>
> Thanks very much in advance.
>
> Nilesh Patel
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.373 / Virus Database: 208 - Release Date: 01/07/2002
>
>

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.373 / Virus Database: 208 - Release Date: 01/07/2002


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




_________________________________________________________________
Join the world?s largest e-mail service with MSN Hotmail. http://www.hotmail.com



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread