Loading TOC...


   $sourceSeq as Sequence,
   $startingLoc as Number,
   [$length as Number]
) as Sequence


Returns the contiguous sequence of items in the value of $sourceSeq beginning at the position indicated by the value of $startingLoc and continuing for the number of items indicated by the value of $length.

In the two-argument case, returns:

$sourceSeq[fn:round($startingLoc) le $p]

In the three-argument case, returns:

$sourceSeq[fn:round($startingLoc) le $p and $p lt fn:round($startingLoc) + fn:round($length)]


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

If $startingLoc is zero or negative, the subsequence includes items from the beginning of the $sourceSeq.

If $length is not specified, the subsequence includes items to the end of $sourceSeq.

If $length is greater than the number of items in the value of $sourceSeq following $startingLoc, the subsequence includes items to the end of $sourceSeq.

The first item of a sequence is located at position 1, not position 0.

For detailed type semantics, see Section 7.2.13 The fn:subsequence functionFS.

The reason the function accepts arguments of type xs:double is that many computations on untyped data return an xs:double result; and the reason for the rounding rules is to compensate for any imprecision in these floating-point computations.

$sourceSeq A Sequence of items from which a subsequence will be selected. If you pass in a single value, it is treated as a Sequence with that single item; therefore, if you pass in an array, fn.subsequence will treat the array as a single-item sequence. If you mean to get the subsequence of each item in the array, then you can call xdmp.arrayValues on the array.
$startingLoc The starting position of the start of the subsequence.
$length The length of the subsequence.


const seq = xdmp.arrayValues(["item1", "item", "item3", "item4" , "..."]);
fn.subsequence(seq, 4)
=> (item4, ...)

const seq = xdmp.arrayValues(["item1", "item", "item3", "item4" , "..."]);
fn.subsequence(seq, 3, 2)
=> (item3, item4)

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.


The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.