home contribute faq download

FunctX XSLT Functions

fn:subsequence

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

Google
Webxsltfunctions.com

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)].

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

NameTypeDescription
$sourceSeq item()* the entire sequence
$startingLoc xs:double the starting item position (1-based)
$length xs:double the number of items to include
return value item()*

Examples

XPath ExampleResults
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)
()

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XSLT Services

Recommended Reading:

XQuery