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

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

This XSLT instruction outputs the values of the child elements

,

, and

(not necessarily exactly one of each), in that order, space-separated.

Numeric Ranges: The
to
Operator

A range expression has the syntax:

Expression
Syntax
RangeExpr
AdditiveExpr (
to
AdditiveExpr )?

The effect is to return a sequence of consecutive integers in ascending order. For example, the expression
1 to 5
returns the sequence
1,2,3,4,5
.

The operands do not have to be constants, of course. A common idiom is to use an expression such as
1 to count($seq)
to return the position number of each item in the sequence
$seq
. If the second operand is less than the first (which it will be in this example if
$seq
is an empty sequence), then the range expression returns an empty sequence. If the second operand is equal to the first, the expression returns a single integer, equal to the value of the first operand.

The two operands must both evaluate to single integers. You can use an untyped value provided it is capable of being converted to an integer; for example, you can write
1 to @width
if
width
is an attribute in a schema-less document containing the value
34
. However, you can't use a decimal or a double value without converting it explicitly to an integer. If you write
1 to @width + 1
, you will get a type error, because the value of
@width + 1
is the double value
35.0e0
. Instead, write
1 to xs:integer(@width) + 1
or
1 to 1 + @width idiv 1
.

Other books

Awakening the Fire by Ally Shields
Burnt Offerings (Valancourt 20th Century Classics) by Robert Marasco, Stephen Graham Jones
Invisible Love by Eric-Emmanuel Schmitt, Howard Curtis
Seducing My Assistant by J. S. Cooper, Helen Cooper
Once an Outlaw by Jill Gregory
The Affair by Freedman, Colette
Bone Coulee by Larry Warwaruk