Name
[2.0] remove()
Given a sequence and a position, removes the item at the requested position.
Syntax
item()*remove(
$target as item()*
,$position as xs:integer
)
Inputs
A sequence and an xs:integer
.
Outputs
This function returns the input sequence with the item at
the requested position removed. If the position is less than
1
or greater than the length of
the sequence, the sequence is returned unchanged. Finally, if the
sequence is the empty sequence, the empty sequence is
returned.
Defined in
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.1, “General Functions and Operators on Sequences.”
Example
To illustrate the remove()
function, we’ll look at
three short stylesheets. Each stylesheet uses a different type of
sequence. The first stylesheet uses a singleton sequence:
<?xml version="1.0"?> <!-- remove1.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="singleton" as="item()*"> <xsl:sequence select="(3)"/> </xsl:variable> <xsl:text>
Here is a test of the remove() </xsl:text> <xsl:text>function:
</xsl:text> <xsl:text>
 Our sequence ($singleton) </xsl:text> <xsl:text>is:
 </xsl:text> <xsl:value-of select="$singleton" separator="
 "/> <xsl:text>

 remove($singleton, 0) = </xsl:text> <xsl:value-of select="remove($singleton, 0)" separator="
 "/> <xsl:text>

 remove($singleton, 7) = </xsl:text> ...
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.