XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (286 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
4.99Mb size Format: txt, pdf, ePub
  • A literal in scientific notation (or to be pedantic, in Fortran notation) is interpreted as an
    xs:double
    value. It starts with the mantissa, which may take the same form as either an integer or a decimal literal, followed by the letter
    E
    in upper or lower case (there is no distinction between the two, though upper case
    E
    is always used on output), followed by an exponent expressed as an integer, optionally preceded by a plus or minus sign. Examples are
    0e0
    ,
    0.314159e+001
    , and
    1.E-6
    .

The production rule for
Digit
is written as a
regular expression
and means that
Digit
is a sequence of one or more characters, each in the range 0 to 9. The square brackets do not mean that the construct is optional, as in some other syntax notations; rather they indicate a range of characters.

You may be wondering why a leading minus sign is not allowed at the front of a numeric literal. The answer is that it is allowed, but it's not part of the literal, so it's not included in these rules. You can write
-1
, but this is technically not a numeric literal; it is an arithmetic expression using a unary minus operator. This operator is described in Chapter 8.

The actual value of the literal is defined in a way that guarantees consistency with the interpretation of values of type
xs:integer
,
xs:decimal
, or
xs:double
by XML Schema. These rules aren't as clear-cut as you might imagine; for example, if you specify a decimal value with more decimal places than your implementation supports, the processor has the option of either rounding the value (in any way it chooses) or reporting an error.

There's a significant change in this area from XPath 1.0, where all numeric values were treated as double-precision floating point. In XPath 1.0, the literal
1.5
represented an
xs:double
; in XPath 2.0, it is an
xs:decimal
. This can affect the precision of numerical calculations. The chances are that the only applications that will notice the change are those that are numerically fairly sophisticated (for example, an XSLT stylesheet that does trigonometrical calculations to produce SVG output). If you have such an application, it may be worth replacing any literals of the form
1.5
by
1.5e0
when you migrate to XPath 2.0.

Other books

Love on the Air by Sierra Donovan
How Do I Love Thee? by Valerie Parv (ed)
Will of Man - Part Two by William Scanlan
The Family Beach House by Holly Chamberlin
London Art Chase by Natalie Grant
Unstable by S.E. Hall
Bella's Tease: Blue Collar Wolves #4 (Mating Season Collection) by Winters, Ronin, Collection, Mating Season
As I Close My Eyes by DiCello, Sarah
Breathe by Melanie McCullough