<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.root.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.root</api:function-name><api:suggest>fn.root</api:suggest><api:suggest>fn</api:suggest><api:suggest>root</api:suggest><api:function-link mode="xquery" fullname="fn:root">/apidoc/8.0/fn:root.xml</api:function-link><api:function mode="javascript" name="root" type="builtin" lib="fn" category="NodeBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.root"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">Returns the root of the tree to which $arg belongs. This will usually, but
not necessarily, be a document node.   
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $arg is the empty sequence, the empty sequence is returned.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If $arg is a document node, $arg is returned.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the function is called without an argument, the context item is used as
the default argument. If the context item is undefined an error is raised:
[err:XPDY0002]. If the context item is not a node an error is raised:
[err:XPTY0004].
</p>
</api:summary><api:params><api:param name="arg" type="node()?" optional="true"><api:param-description>
The node whose root node will be returned.
  </api:param-description><api:param-name>arg</api:param-name><api:param-type>Node?</api:param-type></api:param></api:params><api:return>Node?</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var doc = xdmp.unquote('&lt;a&gt;&lt;quantity&gt;5.0&lt;/quantity&gt;&lt;/a&gt;')
    .toArray()[0];
fn.root(doc);
=&gt; 
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;a&gt;&lt;quantity&gt;5.0&lt;/quantity&gt;&lt;/a&gt;
</pre>
</api:example></api:function></api:function-page>