Description
The fn:id function accepts a sequence of IDs and returns the elements with those IDs. If $node is not provided, the function looks for elements in the same document as the current context item. If $node is provided, the function looks for elements in the same document as $node .
The strings in the $arg sequence can either be individual ID values, or space-separated lists of ID values. Although $arg is a sequence of xs:string values, you can also pass values of type xs:IDREF or xs:IDREFS , since these types are derived from xs:string .
An element is considered to have a particular ID if either:
- It has an attribute, that is marked as an ID, that has that ID value, or
- The type of the element itself is marked as an ID and its content is that particular ID value.
An element or attribute node can become "marked as an ID" by being validated by a schema where it is declared as having type xs:ID , or (for an attribute) being described in a DTD as being of type 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 .
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 ID value to find |
$node |
node() |
a node of the document to look in |
return value |
element()* |
Examples<xsl:variable name="book" select="doc('https://www.datypic.com/functx./input/book.xml')"/>
|
XPath Example | Results |
---|
These examples assume that the input document has been validated, and that the type of the id attribute is xs:ID . |
$book/id('preface') |
<section id="preface">This book introduces XQuery...
The examples are downloadable<fnref ref="fn1"/>...
</section> |
$book/id(
('context','preface')) |
<section id="preface">This book introduces XQuery...
The examples are downloadable<fnref ref="fn1"/>...
</section>
<section id="context">...</section> |
$book/id('context preface') |
<section id="preface">This book introduces XQuery...
The examples are downloadable<fnref ref="fn1"/>...
</section>
<section id="context">...</section> |
$book//section[3]/secRef/id(
@refs) |
<section id="context">...</section> |
$book//section[4]/secRef/id(
@refs) |
<section id="context">...</section>
<section id="language">...Expressions, introduced
in <secRef refs="context"/>, are...
</section> |
$book//secRef/id(@refs) |
<section id="context">...</section>
<section id="language">...Expressions, introduced
in <secRef refs="context"/>, are...
</section> |
$book/id(
('preface','noMatch',
'in!valid')) |
<section id="preface">This book introduces XQuery...
The examples are downloadable<fnref ref="fn1"/>...
</section> |
See AlsoHistory |
Recommended Reading:
|