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

Re: Calculations involving measurements with units

Subject: Re: Calculations involving measurements with units
From: "Paul A. Hoadley" <paulh@xxxxxxxxxxxxxx>
Date: Fri, 2 Jan 2004 23:08:38 +1030
paul hoadley
Hi Ragulf,

On Fri, Jan 02, 2004 at 07:56:47AM +0000, Ragulf Pickaxe wrote:

> The number function returns NaN when the string cannot be expressed
> as a number - therefore this goes wrong.

Should have read the spec on that one---I naively assumed it would
return as much of a number as it could make.

> If you do not know beforehand the units, but need them from the
> string, then you can do a recursive solution taking one letter at a
> time, checking if it is a number. If it is not a number, you print
> out the units.

Thanks for this.  I used a combination of your code and Michael Kay's
suggestion using translate() to strip the units:

<xsl:variable name="upper-margin"
select="concat(number(translate($page-height, translate($page-height,
'0123456789.', ''), '')) div 3.75, translate($page-height,
'012345679.', ''))"/>

Of course, that's quite ugly and I should probably break it out into
separate templates to strip the units and identify the units, but it
works.


-- 
Paul.

mailto:paulh@xxxxxxxxxxxxxx
mailto:phoadley@xxxxxxxxxxxxxxxxxxxxx

 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.