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
8.19Mb 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

Into the Storm by Dennis N.t. Perkins
The Last Street Novel by Omar Tyree
Black Glass by John Shirley
Last Kiss by Laurelin Paige
Silk and Champagne by Brennan, M.M.
Wicked Games by A. D. Justice
The Warrior's Wife by Denise Domning