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

RE: Multiply Element Values

Subject: RE: Multiply Element Values
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Tue, 18 Apr 2000 09:57:59 +0100
xsl multiply
> Task Breakdown:
> -------------
>   * need to multiply qty and price
>   * for each item in the table
>   * display the result in the table
>   * output of each line multiplied needs to be a number
>   * add all costs to get a total
> 
3 approaches:

1 - do the output of the table and the totalling as two separate operations.
The output is straightforward; for the totalling use a recursive template,
with the following pseudo-code:

template name="process-items"
  param item-list
  if $item-list <!-- is not empty -->
    var first = item-list[1]
    var total-of-rest
       call-template process-items with-param item-list[position()!=1]
    /var
    value-of $first/qty * $first/price + $total-of-rest
/template

2 - use the node-set() extension function (in Saxon and xt): create a result
tree fragment that contains the product of qty and price, convert this to a
node-set, and use the sum() function to get the total.

3 - risk being ostracised by the entire XSL community by using saxon:assign
which allows you to update variables.

Mike Kay


 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.