XPath/XQuery reverse function

Summary

Reverses the order of items in a sequence.

Signature

fn:reverse(
$arg as item()*
) as item()*

Properties

This function is deterministic, context-independent, focus-independent, and special-streaming-rules.

Rules

The function returns a sequence containing the items in $arg in reverse order.

Examples

let $abc := ("a", "b", "c")

The expression fn:reverse($abc) returns ("c", "b", "a").

The expression fn:reverse(("hello")) returns ("hello").

The expression fn:reverse(()) returns ().

The expression fn:reverse([1,2,3]) returns [1,2,3].

The expression fn:reverse(([1,2,3],[4,5,6])) returns ([4,5,6],[1,2,3]).

Notes

If $arg is the empty sequence, the empty sequence is returned.