Subject: Re: Calculations involving measurements with units
From: "Paul A. Hoadley" <paulh@xxxxxxxxxxxxxx>
Date: Fri, 2 Jan 2004 23:08:38 +1030
|
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
|