XPath/XQuery string-join function

Summary

Returns a string created by concatenating the items in a sequence, with a defined separator between adjacent items.

Signatures

fn:string-join(
$arg1 as xs:anyAtomicType*
) as xs:string
fn:string-join(
$arg1 as xs:anyAtomicType*,
$arg2 as xs:string
) as xs:string

Properties

This function is deterministic, context-independent, and focus-independent.

Rules

The effect of calling the single-argument version of this function is the same as calling the two-argument version with $arg2 set to a zero-length string.

The function returns an xs:string created by casting each item in the sequence $arg1 to an xs:string, and then concatenating the result strings in order, using the value of $arg2 as a separator between adjacent strings. If the value of $arg2 is the zero-length string, then the members of $arg1 are concatenated without a separator.

Examples

The expression fn:string-join(1 to 9) returns "123456789".

The expression fn:string-join(('Now', 'is', 'the', 'time', '...'), ' ') returns "Now is the time ...".

The expression fn:string-join(('Blow, ', 'blow, ', 'thou ', 'winter ', 'wind!'), '') returns "Blow, blow, thou winter wind!".

The expression fn:string-join((), 'separator') returns "".

The expression fn:string-join(1 to 5, ', ') returns "1, 2, 3, 4, 5".

let $doc :=

The expression $doc//@xml:id ! fn:string-join((node-name(), '="', ., '"')) returns 'xml:id="xyz"'.

The expression $doc//section ! fn:string-join(ancestor-or-self::*/name(), '/') returns "doc/chap/section".

Notes

If the value of $arg1 is the empty sequence, the function returns the zero-length string.