subsequence

A portion of a sequence based on a starting point and length

Description

The fn:subsequence function returns a sequence of $length items of $sourceSeq, starting at the position $startingLoc. The first item in the sequence is considered to be at position 1, not 0. If no $length is passed, or if $length is greater than the number of items that can be returned, the function includes items to the end of the sequence. An alternative to calling the fn:subsequence function is using a predicate. For example, fn:subsequence($a,3,4) is equivalent to $a[position() = (3 to 7)].

Parameters

Description

sourceSeq:item()

the entire sequence

startingLoc:double()

the starting item position (1-based)

length:double()

the number of items to include

Examples

XPath

Results

subsequence((‘a’, ‘b’, ‘c’, ‘d’, ‘e’), 3)

(‘c’, ‘d’, ‘e’)

subsequence((‘a’, ‘b’, ‘c’, ‘d’, ‘e’), 3, 2)

(‘c’, ‘d’)

subsequence((‘a’, ‘b’, ‘c’, ‘d’, ‘e’), 3, 10)

(‘c’, ‘d’, ‘e’)

subsequence((‘a’, ‘b’, ‘c’, ‘d’, ‘e’), 10)

()

subsequence((‘a’, ‘b’, ‘c’, ‘d’, ‘e’), -2, 5)

(‘a’, ‘b’)

subsequence( (), 3)

()