<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.insertBefore.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.insertBefore</api:function-name><api:suggest>fn.insertbefore</api:suggest><api:suggest>fn</api:suggest><api:suggest>insertbefore</api:suggest><api:function-link mode="xquery" fullname="fn:insert-before">/apidoc/8.0/fn:insert-before.xml</api:function-link><api:function mode="javascript" name="insertBefore" type="builtin" lib="fn" category="SequenceBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.insertBefore"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
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.)
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $target is the empty sequence, $inserts is returned. If $inserts is the
empty sequence, $target is returned.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
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.
</p><p xmlns="http://www.w3.org/1999/xhtml">
For detailed semantics see, <a href="http://www.w3.org/TR/xquery-semantics/#sec_fn_insert_before">Section
7.2.15 The fn:insert-before function[FS]</a>.
</p>
</api:summary><api:params><api:param name="target" type="item()*"><api:param-description>
  The sequence of items into which new items will be inserted. 
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">If you pass in a single value, 
  it is treated as a ValueIterator with that single item; therefore, if you 
  pass in an array, the array is treated as a single value (not as one value
  for each item in the array). If you mean to pass in  
  the values of each item in the array, then you can call 
  <a href="./xdmp.arrayValues">xdmp.arrayValues</a> on the array. </span>
  </api:param-description><api:param-name>target</api:param-name><api:param-type>ValueIterator</api:param-type></api:param><api:param name="position" type="xs:integer"><api:param-description>
  The position in the target sequence at which the new items will be added. 
  </api:param-description><api:param-name>position</api:param-name><api:param-type>Number</api:param-type></api:param><api:param name="inserts" type="item()*"><api:param-description>
  The items to insert into the target sequence. 
  <span class="javascript" xmlns="http://www.w3.org/1999/xhtml">If you pass in a single value, 
  it is treated as a ValueIterator with that single item; therefore, if you 
  pass in an array, the array is treated as a single value (not as one value
  for each item in the array). If you mean to pass in  
  the values of each item in the array, then you can call 
  <a href="./xdmp.arrayValues">xdmp.arrayValues</a> on the array. </span>
  </api:param-description><api:param-name>inserts</api:param-name><api:param-type>ValueIterator</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var x = xdmp.arrayValues(["a", "b", "c"]);
fn.insertBefore(x, 0, "z");

=&gt; ("z", "a", "b", "c")

var x = xdmp.arrayValues(["a", "b", "c"]);
fn.insertBefore(x, 1, "z");
=&gt; ("z", "a", "b", "c")

var x = xdmp.arrayValues(["a", "b", "c"]);
fn.insertBefore(x, 2, "z");
=&gt; ("a", "z", "b", "c")

var x = xdmp.arrayValues(["a", "b", "c"]);
fn.insertBefore(x, 3, "z");
=&gt; ("a", "b", "z", "c")

var x = xdmp.arrayValues(["a", "b", "c"]);
fn.insertBefore(x, 4, "z");
=&gt; ("a", "b", "c", "z")
</pre>
</api:example></api:function></api:function-page>