XPath/XQuery idref function

Summary

Returns the sequence of element or attribute nodes with an IDREF value matching the value of one or more of the ID values supplied in $arg.

Signatures

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

Properties

The one-argument form of this function is deterministic, context-dependent, and focus-dependent.
The two-argument form of this function is deterministic, context-independent, and focus-independent.

Rules

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 item (.) if the second argument is omitted. The behavior of the function if $node is omitted is exactly the same as if the context item had been passed as $node.

  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 both of the following conditions are true:

    The is-idrefs property (see ) of $N is true.

    The sequence

    fn:tokenize(fn:normalize-space(fn:string($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 lexically of type xs:ID. These xs:strings are then included in the list of candidate xs:IDs. If any of the 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:NCName]

Examples

let $emp :=

The expression $emp/(element-with-id('ID21256')/@xml:id => fn:idref())/ancestor::employee/last => string() returns "Brown".

The expression $emp/(element-with-id('E30561')/empnr => fn:idref())/ancestor::employee/last => string() returns "Singh".

Error Conditions

A dynamic error is raised 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.

The following errors may be raised when $node is omitted:

If the context item is absent, dynamic error

If the context item is not a node, type error .

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.

Because the function is sensitive to the way in which the data model is constructed, calls on this function are not always interoperable.

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.

If the data model is constructed from a PSVI, the typed value of a node that has the is-idrefs property will contain at least one atomic value of type xs:IDREF (or a type derived by restriction from xs:IDREF). It may also contain atomic values of other types. These atomic values are treated as candidate ID values if two conditions are met: their lexical form must be valid as an xs:NCName, and there must be at least one instance of xs:IDREF in the typed value of the node. If these conditions are not satisfied, such values are ignored.