home contribute faq download

FunctX XQuery Functions

fn:idref

Retrieves elements that refer to other elements based on ID

Google
Webxqueryfunctions.com

Description

The fn:idref function returns the nodes (elements or attributes) that reference one of a specified sequence of IDs. If $node is not provided, the function looks for elements and attributes in the same document as the current context item. If $node is provided, the function looks for elements and attributes in the same document as $node.

In order to be considered to reference an ID, the node must be marked as an IDREF or IDREFS type, and it must contain that ID value. Generally, this means that it was declared to be of type xs:IDREF or xs:IDREFS in an in-scope schema definition. If it is an IDREFS value, only one of the values in the list need match the ID. The default collation is not used to match ID values; a simple comparison of Unicode code points is used.

The function returns the nodes in document order, not the order designated by the sequence of $arg values. The result sequence contains no duplicate elements, even if an ID value was included twice in $arg. However, there may be several elements or attributes in the results that reference the same ID.

This description is © Copyright 2007, Priscilla Walmsley. It is excerpted from the book XQuery by Priscilla Walmsley, O'Reilly, 2007. For a complete explanation of this function, please refer to Appendix A of the book.

Arguments and Return Type

NameTypeDescription
$arg xs:string* the IDREF value to find references to
$node node() a node of the document to look in
return value node()*

Examples

let $book :=
doc('http://www.functx.com/input/book.xml')
return
XQuery ExampleResultsExplanation
It is assumed that the input document has been validated, that the type of the id and fnid attributes is xs:ID, the type of the ref attribute is xs:IDREF, and the type of the refs attribute is xs:IDREFS.
$book/idref('language')/string(.)
context language
String value of the refs attribute of the second secRef element
$book/idref('context')/string(.)
('context', 'context language')
String value of the refs attributes of both secRef elements
$book/idref(
   ('context', 'language') )/string(.)
('context', 'context language')
String value of the refs attributes of both secRef elements
$book//fn[1]/idref(@fnid)/string(.)
fn1
String value of the ref attribute of the fnRef element
$book/idref(('language',
    'noMatch', 'in!valid') )/string(.)
context language
String value of the refs attribute of the second secRef element

See Also

fn:idRetrieves elements by their ID
functx:id-untypedGets XML element(s) that have an attribute with a particular value
functx:id-from-elementGets the ID of an XML element

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26W3C, XQuery 1.0 and XPath 2.0 Functions and Operators, http://www.w3.org/TR/xpath-functions/
Datypic XQuery Services

Recommended Reading:

XQuery