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 TypeName | Type | Description |
$arg |
xs:string* |
the IDREF value to find references to |
$node |
node() |
a node of the document to look in |
return value |
node()* |
Exampleslet $book := | doc('http://www.datypic.com/functx./input/book.xml') | return |
XQuery Example | Results | Explanation |
---|
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 AlsoHistory |
Recommended Reading:
|