mirror of
https://github.com/alexandrev/xslt-lab.git
synced 2026-09-18 19:43:16 +00:00
53e90ef86e
Full coverage of XSLT 1.0, 2.0 and 3.0 elements and XPath functions: - 59 XSLT elements (xsl:stylesheet → xsl:use-accumulators) - 170 XPath functions (1.0 node/string/numeric/boolean, 2.0 sequence/ date/QName/string, 3.0 HOF/map/array/JSON/streaming) Each page: description, parameters table, return value, 2 runnable Saxon examples with input XML + stylesheet + output, notes, cross-links. xsltCompletions.js: all 229 entries now have blogSlug for hover links. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
3.1 KiB
3.1 KiB
title, description, date, version, versionLabel, category, syntax, tags
| title | description | date | version | versionLabel | category | syntax | tags | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| remove() | Returns a new sequence with the item at a specified 1-based position removed, without modifying the original sequence. | 2026-04-18T00:00:00Z | 2.0 | XSLT 2.0 | sequence function | remove(sequence, position) |
|
Description
remove() produces a new sequence that is identical to the input sequence except that the item at the specified 1-based position is omitted. Positions are 1-based. The original sequence is not modified.
If position is less than 1 or greater than the length of the sequence, the entire sequence is returned unchanged — no error is raised.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sequence |
item()* | Yes | The source sequence. |
position |
xs:integer | Yes | The 1-based position of the item to remove. |
Return value
item()* — the sequence with the item at position omitted. The length is count($sequence) - 1 if position was valid.
Examples
Removing the first item
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:variable name="nums" select="(10, 20, 30, 40, 50)"/>
<!-- Remove item at position 1 -->
<xsl:variable name="tail" select="remove($nums, 1)"/>
<result>
<xsl:value-of select="$tail" separator=", "/>
</result>
</xsl:template>
</xsl:stylesheet>
Output:
<result>20, 30, 40, 50</result>
Removing a specific element from a node sequence
Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
<item>Home</item>
<item>About</item>
<item>Blog</item>
<item>Contact</item>
</menu>
Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/menu">
<!-- Remove the 'Blog' item (position 3) -->
<xsl:variable name="items" select="item"/>
<xsl:variable name="filtered" select="remove($items, 3)"/>
<nav>
<xsl:for-each select="$filtered">
<link><xsl:value-of select="."/></link>
</xsl:for-each>
</nav>
</xsl:template>
</xsl:stylesheet>
Output:
<nav>
<link>Home</link>
<link>About</link>
<link>Contact</link>
</nav>
Notes
remove()only removes one item per call. To remove multiple items by position, chain calls or usesubsequence()combined with sequence concatenation.- To remove items by value rather than position, use a filter predicate:
$seq[. != $value]. - Out-of-range positions (< 1 or > length) are silently ignored; the full sequence is returned.
- Equivalent to
($seq[position() lt $pos], $seq[position() gt $pos])but more readable.