Subject: Re: [xsl] How to access calculation done in loop? From: Jiri Jirat <Jiri.Jirat@xxxxxxxxx> Date: Fri, 02 Feb 2001 09:01:39 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to access calculation don, Niloy Chakrabarty | Thread | RE: [xsl] How to access calculation, Michael Kay |
Re[2]: [xsl] Javascript Function wi, viewga | Date | "Deep-Equal Nodes" (Was: RE: [xsl] , Dimitre Novatchev |
Month |