Loading TOC...

MarkLogic Server 11.0 Product Documentation
fn:insert-before

fn:insert-before(
   $target as item()*,
   $position as xs:integer,
   $inserts as item()*
) as item()*

Summary

Returns a new sequence constructed from the value of $target with the value of $inserts inserted at the position specified by the value of $position. (The value of $target is not affected by the sequence construction.)

If $target is the empty sequence, $inserts is returned. If $inserts is the empty sequence, $target is returned.

The value returned by the function consists of all items of $target whose index is less than $position, followed by all items of $inserts, followed by the remaining elements of $target, in that sequence.

If $position is less than one (1), the first position, the effective value of $position is one (1). If $position is greater than the number of items in $target, then the effective value of $position is equal to the number of items in $target plus 1.

For detailed semantics see, Section 7.2.15 The fn:insert-before function[FS].

Parameters
target The sequence of items into which new items will be inserted.
position The position in the target sequence at which the new items will be added.
inserts The items to insert into the target sequence.

Example

let $x := ("a", "b", "c")
return
fn:insert-before($x, 0, "z") returns ("z", "a", "b", "c")

let $x := ("a", "b", "c")
return
fn:insert-before($x, 1, "z") returns ("z", "a", "b", "c")

let $x := ("a", "b", "c")
return
fn:insert-before($x, 2, "z") returns ("a", "z", "b", "c")

let $x := ("a", "b", "c")
return
fn:insert-before($x, 3, "z") returns ("a", "b", "z", "c")

let $x := ("a", "b", "c")
return
fn:insert-before($x, 4, "z") returns ("a", "b", "c", "z")

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.