insert-before function
The fn:insert-before function inserts a sequence before a specific position in another sequence.
Syntax
- source-sequence
- The sequence into which a sequence is to be inserted.
source-sequence is a sequence of items of any data type, or is the empty sequence.
- insert-position
- The position in source-sequence before which a sequence is to be inserted. insert-position has the xs:integer data type. If insert-position<=0, insert-position is set to 1. If insert-position is greater than the number of items in source-sequence, insert-position is set to one greater than the number of items in source-sequence.
- insert-sequence
- The sequence that is to be inserted into source-sequence.
insert-sequence is a sequence of items of any data type, or is the empty sequence.
Returned value
If source-sequence is
not the empty sequence:
- If insert-sequence is not the empty sequence, the returned
value is a sequence with the following items, in the following order:
- The items in source-sequence before item insert-position
- The items in insert-sequence
- The item in source-sequence at item insert-position
- The items in source-sequence after item insert-position
- If insert-sequence is the empty sequence, the returned value is source-sequence.
If source-sequence is the empty sequence:
- If insert-sequence is not an empty sequence, the returned value is insert-sequence.
- If insert-sequence is an empty sequence, the returned value is the empty sequence.
Example
The following function returns the
sequence that results from inserting the sequence (4,5,6) before position
4 in sequence (1,2,3,7):
fn:insert-before((1,2,3,7),4,(4,5,6))
The returned value is (1,2,3,4,5,6,7).