Subject: [xsl] Re: result = node1 * node2 and then get total of all the result from whole document at the end From: Dimitre Novatchev <dnovatchev@xxxxxxxxx> Date: Wed, 2 Jan 2002 02:43:20 -0800 (PST) |
> I am having hard > time adding the product of rate and quantity into a variable and then > increment it and print it at the end of document. http://www.dpawson.co.uk/xsl/sect2/N5121.html#d154e138 Look at the link "Quantity times price". The corresponding functional solution in Haskell is: sumOfProducts :: Num a => [[a]] -> a sumOfProducts = sum . (map product) where: sum :: (Num a) => [a] -> a sum = foldl add 0 and product :: (Num a) => [a] -> a product = foldl multiply 1 sumOfProducts() takes a list of lists of numbers, first "map" produces a new list whose elements are the products of the numbers contained in every element (which is itself a list of numbers), then finally "sum" sums the (products) elements of this new list. For example: sumProducts [[1,2,3],[3,4]] evaluates to 18 (sum [1*2*3, 3*4] = sum [6, 12] = 6 + 12 = 18). As can be seen this is much more powerful function, allowing to sum not only products of pairs, but products of lists of numbers with varying length. The XSLT implementation of this functional solution is straightforward and left as an exercise for the interested readers. Cheers, Dimitre Novatchev. __________________________________________________ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Re: XPath incompatibiliti, Jeni Tennison | Thread | RE: [xsl] Wishes for XSL revisions , Michael Kay |
RE: [xsl] Re: XPath incompatibiliti, Michael Kay | Date | RE: [xsl] Wishes for XSL revisions , Michael Kay |
Month |