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

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.13Mb size Format: txt, pdf, ePub

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
(

([

”])*

)+
| (
'
([

'])*
'
)+

Other books

The Justice Game by RANDY SINGER
Reinventing Emma by Emma Gee
Love Is for Tomorrow by Michael Karner, Isaac Newton Acquah
Requiem for the Dead by Kelly Meding
Drawing Down the Moon by Margot Adler
The bride wore black by Cornell Woolrich
Wartime Sweethearts by Lizzie Lane