Name

[2.0] subsequence()

Returns a contiguous portion of a sequence.

Syntax

item()* subsequence($sourceSeq as item()*, $startingLoc as xs:double)
item()* subsequence($sourceSeq as item()*, $startingLoc as xs:double, 
                    $length as xs:double)

Inputs

A sequence and a starting position. An optional third argument specifies the number of items to be returned. The second and third arguments are xs:doubles because many numeric operations on untyped data return xs:double.

Some details about how the two numeric arguments work:

  • If the starting position is larger than the number of items in the sequence, the empty sequence is returned.

  • If the sequence is the empty sequence, the empty sequence is returned.

Outputs

A new sequence containing the specified items.

Defined in

XQuery 1.0 and XPath 2.0 Functions and Operators section 15.1, “General Functions and Operators on Sequences.”

Example

Here’s a stylesheet that illustrates how subsequence() works:

<?xml version="1.0"?>
<!-- subsequence.xsl --> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:variable name="testSequence" as="item()*"> <xsl:sequence select="(3, 4, 5)"/> <xsl:element name="currentDate"> <xsl:value-of select="current-date()"/> </xsl:element> <xsl:element name="currentTime"> <xsl:value-of select="current-time()"/> </xsl:element> <xsl:element name="integerTest"> <xsl:value-of select="xs:integer(8)"/> </xsl:element> ...

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.