<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.id.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.id</api:function-name><api:suggest>fn.id</api:suggest><api:suggest>fn</api:suggest><api:suggest>id</api:suggest><api:function-link mode="xquery" fullname="fn:id">/apidoc/8.0/fn:id.xml</api:function-link><api:function mode="javascript" name="id" type="builtin" lib="fn" category="SequenceBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.id"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
Returns the sequence of element nodes that have an ID value matching the value
of one or more of the IDREF values supplied in $arg.
</p>

</api:summary><api:params><api:param name="arg" type="xs:string*"><api:param-description>
The IDs of the elements to return.
  </api:param-description><api:param-name>arg</api:param-name><api:param-type>String[]</api:param-type></api:param><api:param name="node" type="node()" optional="true"><api:param-description>
The target node.
  </api:param-description><api:param-name>node</api:param-name><api:param-type>Node</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:usage>
<p xmlns="http://www.w3.org/1999/xhtml">
The function returns a sequence, in document order with duplicates eliminated,
containing every element node E that satisfies all the following conditions:
</p>
<ol xmlns="http://www.w3.org/1999/xhtml"><li>E is in the target document. The target document is the document containing
$node, or the document containing the context node if the second argument is
omitted. An error is raised [err:FODC0001] if $node, or the context item if
the second argument is omitted, is a node in a tree whose root is not a
document node or if the second argument is omitted and there is no context
item [err:FONC0001], or if the context item is not a node [err:FOTY0011].
</li><li>E has an ID value equal to one of the candidate IDREF values, where:
<ul><li>An element has an ID value equal to V if either or both of the following
conditions are true:
<ul><li>The is-id property (See Section 5.5 is-id AccessorDM.) of the element node
is true, and the typed value of the element node is equal to V under the
rules of the eq operator using the Unicode code point collation
  (http://www.w3.org/2005/xpath-functions/collation/codepoint).
</li><li>The element has an attribute node whose is-id property (See Section 5.5
is-id AccessorDM.) is true and whose typed value is equal to V under the
rules of the eq operator using the Unicode code point collation
  (http://www.w3.org/2005/xpath-functions/collation/codepoint).
</li></ul>
</li><li>Each xs:string in $arg is parsed as if it were of type IDREFS, that is,
each xs:string in $arg is treated as a space-separated sequence of tokens,
each acting as an IDREF. These tokens are then included in the list of
candidate IDREFs. If any of the tokens is not a lexically valid IDREF (that
is, if it is not lexically an xs:NCName), it is ignored. Formally, The
candidate IDREF values are the strings in the sequence given by the
expression:
<pre xml:space="preserve">
for $s in $arg
return fn:tokenize(fn:normalize-space($s), ' ')
                 [. castable as xs:IDREF]
</pre>
</li></ul>
</li><li>If several elements have the same ID value, then E is the one that is first
in document order.
</li></ol>
<p xmlns="http://www.w3.org/1999/xhtml">Notes:</p>
<p xmlns="http://www.w3.org/1999/xhtml">
If the data model is constructed from an Infoset, an attribute will have the
is-id property if the corresponding attribute in the Infoset had an attribute
type of ID: typically this means the attribute was declared as an ID in a DTD.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the data model is constructed from a PSVI, an element or attribute will have
the is-id property if its schema-defined type is xs:ID or a type derived by
restriction from xs:ID.
</p><p xmlns="http://www.w3.org/1999/xhtml">
No error is raised in respect of a candidate IDREF value that does not match
the ID of any element in the document. If no candidate IDREF value matches the
ID value of any element, the function returns the empty sequence.
</p><p xmlns="http://www.w3.org/1999/xhtml">
It is not necessary that the supplied argument should have type xs:IDREF or
xs:IDREFS, or that it should be derived from a node with the is-idrefs
property.
</p><p xmlns="http://www.w3.org/1999/xhtml">
An element may have more than one ID value. This can occur with synthetic data
models or with data models constructed from a PSVI where an the element and one
of its attributes are both typed as xs:ID.
</p><p xmlns="http://www.w3.org/1999/xhtml">
If the source document is well-formed but not valid, it is possible for two or
more elements to have the same ID value. In this situation, the function will
select the first such element.
</p><p xmlns="http://www.w3.org/1999/xhtml">
It is also possible in a well-formed but invalid document to have an element or
attribute that has the is-id property but whose value does not conform to the
lexical rules for the xs:ID type. Such a node will never be selected by this
function.
</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var x = xdmp.unquote('&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;'
   + '&lt;p id="myID"&gt;hello&lt;/p&gt;' 
  + '&lt;/html&gt;');
fn.id("myID", x.toArray()[0]);

=&gt; &lt;p id="myID" xmlns="http://www.w3.org/1999/xhtml"&gt;hello&lt;/p&gt;
</pre>
</api:example></api:function></api:function-page>