Allows you to create a new sequence by inserting items into an existing sequence.
$target as item()*,
$position as xs:integer,
$inserts as item()*
A sequence, an
(a position), and a second sequence.
A new sequence in which the second sequence has been inserted into the first sequence before the item at the requested position.
The rules for
insert-before() are what you’d
expect. If the first sequence is empty, the second sequence is
returned unchanged. If the second sequence is empty, the first
sequence is returned unchanged. If the position is less than
1, the processor inserts the
second sequence at the start of the first. Finally, if the
position is greater than the number of items in the first
sequence, the second sequence is inserted at the end of the
XQuery 1.0 and XPath 2.0 Functions and Operators section 15.1, “General Functions and Operators on Sequences.”
Here’s a stylesheet that uses
insert-before() in several
<?xml version="1.0"?> <!-- insert-before.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="longSequence" as="item()*"> <xsl:sequence select="(3, 4, 5, current-date(), current-time(), 8, 'blue')"/> </xsl:variable> <xsl:variable name="shortSequence" as="item()*" select="(current-dateTime(), xs:yearMonthDuration('P3Y8M'))"/> ...