[2.0] idref()

Given a sequence of ID values, returns a sequence containing all the nodes with an IDREF value matching one of the given IDs.


node()* idref(xs:string*)
node()* idref(xs:string*, node())


A sequence of xs:strings, each of which represents an ID value. If the node() argument is supplied, the XSLT processor looks for matching IDREF and IDREFS values in the document that contains that node. Without the node() argument, the processor looks in the document that contains the context node.


A sequence of nodes, each of which has an IDREF or IDREFS value that matches one of the given IDs. The nodes are returned in document order, and any duplicate nodes are removed.

Defined in

XQuery 1.0 and XPath 2.0 Functions and Operators section 15.5, “Functions and Operators that Generate Sequences.”


For our example, we’ll use a list of components and parts with an embedded DTD. We’ll list each part, followed by the name of each component that uses that part. The idref() function lets us retrieve the <component> element with the specific ID; from there we can get the name of the component.


This is the exact opposite of the example for the id() function. In that example, we take each <component> and list all of the parts that it uses.

To illustrate the idref() function, we’ll use an XML document with an embedded DTD. (This allows us to demonstrate the function without requiring a schema-aware XSLT processor.) Here is a fragment of the document:

<?xml version="1.0"?> ...

Get XSLT, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.