Re: [xsl] Floating point numbers in XPath

Subject: Re: [xsl] Floating point numbers in XPath
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 9 Apr 2002 16:49:39 +0100
Hi Curtis,

>You said:
>
>>[134] DoubleLiteral ::= (("." [0-9]+) |
>>        ([0-9]+ ("." [0-9]*)?))
>>        ([e] | [E]) ([+] | [-])? [0-9]+
>
>The first bit caught my attention: ("." [0-9]+)
>This appears to me to be incorrect. It would allow .0 as a valid
>DoubleLiteral, and runs counter to the other rules you mentioned. (+-0 -
>
>> "0"; 0.1 -> "0.1"; ".1" is invalid because there are <1 digits to the
>
>left of the decimal point.)
>
>Comments? It's possible I'm just having my usual lousy Tuesday...

The DoubleLiteral production is about what will be recognised in an
XPath expression as a xs:double. So you can have:

  1.0E-6

as a valid double literal, but also have:

  10e+2
  .02e+7

and so on. These are all valid lexical representations of xs:double
values.

As you'll notice, this means that there are several valid lexical
representations for any particular xs:double; the same's true with
numbers in normal XPath -- you can have 10 or 10.000 in an expression
and it won't make any difference to the number that the XPath
processor actually uses when it performs a calculation.

This is all to do with what an XPath processor will accept within an
XPath expression that you write. The other side of the coin is what an
XPath processor will *produce* when you convert one of these values to
a string. Since there are lots of lexical representations of the same
number, the XPath processor has to choose which one to use. Since we
want all the XPath processors to behave in the same way, someone has
to write down the rules about what these processors will create.

This is where the canonical lexical representations come in. Canonical
lexical representation rules take you from a value to a string (e.g.
some output). Using a canonical lexical representation means that you
can guarantee that every processor will produce exactly the same
string when you give it a particular number.

Interestingly enough, there are some data types defined in XML Schema
without canonical lexical representations (see
http://lists.w3.org/Archives/Public/www-xml-query-comments/2002Jan/0268.html).

Cheers,

Jeni

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


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread