<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/fn.idref.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>fn.idref</api:function-name><api:suggest>fn.idref</api:suggest><api:suggest>fn</api:suggest><api:suggest>idref</api:suggest><api:function-link mode="xquery" fullname="fn:idref">/apidoc/8.0/fn:idref.xml</api:function-link><api:function mode="javascript" name="idref" type="builtin" lib="fn" category="SequenceBuiltins" bucket="W3C-Standard Functions" hidden="false" prefix="fn" namespace="http://www.w3.org/2005/xpath-functions" fullname="fn.idref"><api:summary>
<p xmlns="http://www.w3.org/1999/xhtml">
Returns the sequence of element or attribute nodes that have an IDREF value
matching the value of one or more of the ID values supplied in $arg.
</p>
</api:summary><api:params><api:param name="arg" type="xs:string*"><api:param-description>
The IDREFs of the elements and attributes 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 or attribute node $N that satisfies all the following
// conditions:
</p>
<ol xmlns="http://www.w3.org/1999/xhtml"><li>$N 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>$N has an IDREF value equal to one of the candidate ID values, where:
<ul><li>A node $N has an IDREF value equal to V if either or both of the following
conditions are true:
<ul><li>The is-idrefs property (See Section 5.6 is-idref AccessorDM.) of $N is true.
</li><li>
The sequence
fn:tokenize(fn:normalize-space($N), ' ')
contains a string that 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 xs:ID.  These
xs:strings are then included in the list of candidate xs:IDs. If any of the
xs:strings in $arg is not a lexically valid xs:ID (that
is, if it is not lexically an xs:NCName), it is ignored. More formally, The
candidate ID values are the strings in the sequence
<pre xml:space="preserve">
$arg[. castable as xs:ID]
</pre>
</li></ul>
</li></ol>
<p xmlns="http://www.w3.org/1999/xhtml">Notes:</p>
<p xmlns="http://www.w3.org/1999/xhtml">
An element or attribute typically acquires the is-idrefs property by being
validated against the schema type xs:IDREF or xs:IDREFS, or (for attributes
only) by being described as of type IDREF or IDREFS in a DTD.
</p><p xmlns="http://www.w3.org/1999/xhtml">
No error is raised in respect of a candidate ID value that does not match the
IDREF value of any element or attribute in the document. If no candidate ID
value matches the IDREF value of any element or attribute, the function returns
the empty sequence.
</p><p xmlns="http://www.w3.org/1999/xhtml">
It is possible for two or more nodes to have an IDREF value that matches a
given candidate ID value. In this situation, the function will return all such
nodes. However, each matching node will be returned at most once, regardless
how many candidate ID values it matches.
</p><p xmlns="http://www.w3.org/1999/xhtml">
It is possible in a well-formed but invalid document to have a node whose
is-idrefs property is true but that does not conform to the lexical rules for
the xs:IDREF type. The effect of the above rules is that ill-formed candidate
ID values and ill-formed IDREF values are ignored
</p>
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
//   assume /mydocs/idref.xml has an element named idrefs that is
//   of type xs:IDREF or xs:IDREFS

fn.idref("myID", fn.doc("/mydocs/idref.xml").toArray()[0]);

=&gt; &lt;idrefs&gt;myID&lt;/idrefs&gt;
</pre>
</api:example></api:function></api:function-page>