MarkLogic Server 11.0 Product Documentation
fn:idref

fn:idref(
   $arg as xs:string*,
   [$node as node()]
) as node()*

Summary

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.

Parameters
arg The IDREFs of the elements and attributes to return.
node The target node.

Usage Notes

The function returns a sequence, in document order with duplicates eliminated, containing every element or attribute node $N that satisfies all the following // conditions:

  1. $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].
  2. $N has an IDREF value equal to one of the candidate ID values, where:
    • A node $N has an IDREF value equal to V if either or both of the following conditions are true:
      • The is-idrefs property (See Section 5.6 is-idref AccessorDM.) of $N is true.
      • 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).
    • 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
      $arg[. castable as xs:ID]
      

Notes:

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.

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.

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.

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

Example

(:
   assume /mydocs/idref.xml has an element named idrefs that is
   of type xs:IDREF or xs:IDREFS
:)
fn:idref("myID", doc("/mydocs/idref.xml"))

=> <idrefs>myID</idrefs>
Powered by MarkLogic Server | Terms of Use | Privacy Policy