Version:

Loading TOC...

MarkLogic Server 11.0 Product Documentation

fn:subsequencefn:subsequence( $sourceSeq as item()*, $startingLoc as xs:double, [$length as xs:double] ) as item()*

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`

.

As described in https://www.w3.org/TR/xpath-functions/:

In the two-argument case, `fn.subsequence`

returns a sequence comprising those items of
`$sourceSeq`

whose index position (counting from one) is greater than or equal to the
value of `$startingLoc`

(rounded to an integer):

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

No error occurs if `$startingLoc`

is zero or negative.

In the three-argument case, The function returns a sequence comprising those items of
`$sourceSeq`

whose index position (counting from one) is greater than or equal to the
value of `$startingLoc`

(rounded to an integer), and less than the sum of
`$startingLoc`

and `$length`

(both rounded to integers):

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

No error occurs if `$startingLoc`

is zero or negative, or if `$startingLoc`

plus `$length`

exceeds the number of items in the sequence, or if
`$length`

is negative.

Notes:

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 functional specification.

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.

Parameters | |
---|---|

$sourceSeq | The sequence of items from which a subsequence will be selected. |

startingLoc | The starting position of the start of the subsequence. |

length | The length of the subsequence. |

Assume $seq = ($item1, $item2, $item3, $item4, ...) fn:subsequence($seq, 4) returns ($item4, ...) fn:subsequence($seq, 3, 2) returns ($item3, $item4)

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