Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
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.