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

Re: How to access calculation done in loop?

Subject: Re: How to access calculation done in loop?
From: Jiri Jirat <Jiri.Jirat@xxxxxxxxx>
Date: Fri, 02 Feb 2001 09:01:39 +0100
access calculation
Hello, 
 try the example below.
Note, that it is not necessary to use node-set()
extension function in case of saxon (does conversion
automatically).

Best regards
Jirka


XML
<box>
 <item><qty>2</qty><price>3</price></item>
 <item><qty>3</qty><price>4</price></item>
 <item><qty>5</qty><price>6</price></item>
</box>

XSLT

<xsl:stylesheet 
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform' 
  xmlns:saxon="http://icl.com/saxon" extension-element-prefixes="saxon"
  version="1.0">

<xsl:template match="/box">
 <xsl:variable name="all">
   <xsl:apply-templates select="/box/item" mode="qty_times_price"/>
 </xsl:variable>

 <result>
   <xsl:value-of select="sum(saxon:node-set($all)/tmp)"/>
 </result>
</xsl:template>

<xsl:template match="item" mode="qty_times_price">
 <tmp><xsl:value-of select="qty*price"/></tmp>
</xsl:template>

</xsl:stylesheet>


Output:
<?xml version="1.0" encoding="utf-8"?>
<result>48</result>

Best regards
Jirka


Niloy Chakrabarty wrote:
> 
> Hi,
> 
> I am trying to calculate the total price of all the items purchased. Take for
> example the code below:
> 
> <xsl:for-each select="//box/item">
>   <xsl:value-of select="./price"/>
>   <xsl:value-of select="./qty"/>
> </xsl:for-each>
> 
> I want to print the total amount outside the for-each loop by multiplying
> price and qty for each item. Is there a way to achieve this?
> 
> TIA
> 
> Niloy
> 
> ____________________________________________________________________
> Get free email and a permanent address at http://www.netaddress.com/?N=1
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
 <name firstName="Jirka" surname="Jirat"/>
 <mail>     jiratj@xxxxxxxxx  </mail>
 <support>  http://www.zvon.org </support>
 <zvonMailingList> http://www.zvon.org/index.php?nav_id=4
</zvonMailingList>

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


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.