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

Re: Calculations in XSL using multiple XML data fileds

Subject: Re: Calculations in XSL using multiple XML data fileds
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 1 Nov 2000 10:02:25 -0400 (EST)
xpath decimal places
Phil,

>These fields will always contain numeric data and need to return a result to
>2 decimal places
>
>I want the XSL to perform the following calculation
>
>	(q1/quotes/quote/last) - ((q2/quotes/quote/last)/7.45)
>
>I am hoping that this can be done in XSL but cannot find out how this can be
>done.

The only thing you're lacking is knowing how to divide in XSLT (well,
actually in XPath).  The '/' can't be used because it's used in XPath to
separate steps, so instead 'div' is used instead:

  q1/quotes/quote/last - (q2/quotes/quote/last div 7.45)

To give the result to two decimal places, you need the format-number() XSLT
function:

  format-number(q1/quotes/quote/last - (q2/quotes/quote/last div 7.45),
                '#,##0.00')

>I am using IIS5, the XML is generated from an HTTP request made to a
>proprietry XML database via an ASP page.

How the XML is generated won't matter in terms of how you solve this
problem, but what XSLT processor you're using will: if you're using MSXML,
make sure it's the latest version.

>If it cannot be done in XSL, can anyone suggest how else (script?) this can
>be done

If you're using MSXML, then you can use an extension function called
msxsl:script to write functions in JScript or VBScript that can then be
used within XPath as XPath functions.  XSLT is enough to handle simple
calculations, but if you get anything complicated (e.g. sin/cos) then you
need something more, which msxsl:script provides.  The details are given in
the MSXML SDK.

I hope that this helps,

Jeni

Jeni Tennison
http://www.jenitennison.com/




 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.