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

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

Usage

Often
compare()
is followed by a three-way branch. Because XPath has no switch or case expression, it is best to assign the result of the function to a variable to avoid doing the comparison twice. For example, in XSLT:



    … 

    … 

    … 


Or, in XQuery 1.0:

let $c := compare(A, B) return

    if ($c = -1) then …

    else if ($c = 0) then …

    else …

In pure XPath 2.0, you can do this rather awkwardly with a
for
expression:

for $c in compare(A, B) return

    if ($c = -1) then …

    else if ($c = 0) then …

    else …

See Also

Collations
on page 459 in Chapter 6

Value Comparisons
on page 581 in Chapter 8

concat

The
concat()
function takes two or more arguments. Each of the arguments is converted to a string, and the resulting strings are joined together end-to-end.

For example, the expression
concat(‘Jane’, ‘ ’, ‘Brown’)
returns the string
Jane Brown
.

Changes in 2.0

None.

Signature

This function is unique in that it can take any number of arguments (two or more).

Argument
Type
Meaning
value
(repeated)
xs:anyAtomicType
A string to be included in the result
Result
xs:string
The result of concatenating each of the arguments in turn

Effect

Each of the supplied strings is appended to the result string, in the order they appear.

Any argument that is an empty sequence is ignored. If all the arguments are empty sequences, the result is a zero-length string.

Note that all the arguments will automatically be cast to strings.

Examples

Expression
Result
concat(“a”, “b”, “c”)
The string
abc
concat(“chap”, 3)
The string
chap3
concat(“a”, (), (), “b”)
The string
ab
concat(“a”, (“b”, “c”))
In 1.0 mode: the string
ab
(when a sequence is converted to a string in backward-compatibility mode, all items after the first are discarded).
In 2.0 mode: error. The argument must be a single string, not a sequence of strings. Use the
string-join()
function instead.

Other books

Wild Is the Night by Colleen Quinn
Eat Less Fatty by Scott, Anita
Unzipped? by Karen Kendall
Black Eagle by Gen Bailey
Dragons' Onyx by Richard S. Tuttle
Restless Soul by Alex Archer
Rebekah Redeemed by Dianne G. Sagan