Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
These rules have the effect that you often don't need to know whether the numbers you are dealing with are integers, decimals, or doubles. For example, if
@width
is an attribute in a schema-less document whose value is
width=“17”
, then the value of
string(@width+1)
is
18
; you never need to know that the result of the addition was actually an
xs:double
(the rules for arithmetic involving mixed types are in Chapter 8).
If you want more control over the formatting of numeric output, XSLT has a function
format-number(),
which offers detailed control. There's nothing comparable in XPath itself, but you can get rid of surplus decimal digits by using the
round-half-to-even()
function described in Chapter 13.
Examples
Expression | Description |
86 | The xs:integer value eighty-six |
3.14159 | An xs:decimal value representing π to five decimal places |
1.0E-6 | The xs:double value one-millionth |
Changes in XPath 2.0
XPath 1.0 supported the lexical forms now used for integer literals and decimal literals, but interpreted the values as double-precision floating point. There was no support in XPath 1.0 for scientific notation.
String Literals
A
StringLiteral
represents a constant string.
Symbol | Lexical Rules |
StringLiteral | ( “ ([ ∧ ”])* “ )+ | ( ' ([ ∧ '])* ' )+ |