id

Retrieves elements by their ID

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.

Parameters

Description

arg:string()

the ID value to find

node:node()

a node of the document to look in

Examples

XPath

Results

See Also