RE: [xsl] XPath / XSLT 2.1 - Rounding algorithms

Subject: RE: [xsl] XPath / XSLT 2.1 - Rounding algorithms
From: "Rushforth, Peter" <prushfor@xxxxxxxxxxx>
Date: Fri, 14 Nov 2008 09:51:41 -0500
Hi Michael,

> > round(3.065) returns 3. , whereas my need is for a function
> to return
> > 3.07 (say), something like this, say:
> >
> > round-half-up(3.065,2) -> 3.07
> > round-half-up(-3.065,2) -> -3.07
> You can always multiply by a hundred, round(), and then
> divide by a hundred.

Thanks for the algorithm, I'll try it out.

> I know it's tedious but there was a lot of feeling in the WG
> that we should have a library of a hundred functions rather
> than a thousand, if we were to have a reasonable prospect of
> making the spec implementable (not to mention the task of
> actually writing it and publishing it).

The round-half-to-even() function _is_ available, yet it's only part
of the standard, so it's an odd place to draw the line.

I understand the hesitation to increase the burden of implementation,
especially for open-source implementation providers.  Not being an
implementer, it's easy to talk, you might say.

But I also think that should be balanced against the barriers to entry
on the part of potential XSLT programmers.   Having to understand
functions and the limitations of what can be achieved
directly in XSLT / XPath takes time and raises the bar for potential
users. A certain 'core' set of math functions for XPath could be an
important addition - there are lots of mathematical uses for XSLT and

Having the ability to create one's own XPath functions was a fabulous
but it doesn't apply across languages dependant on XPath, the functions
must be
re-written in each language.  But here I'm just talking about one
and as far as I know it's not in either the EXSLT math library or
Dimitre's FXSL library.


Current Thread