O'Reilly logo

XSLT by Doug Tidwell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

id() Function — Returns the node in the source tree whose ID attribute matches the value passed in as input.

Synopsis

node-set id(
               object
               )

Inputs

An object. If the input object is a node-set, the result is a node-set that contains the result of applying the id() function to the string value of each node in the argument node-set. Usually, the argument is some other node type, which is (or is converted to) a string. That string is then used as the search value while all attributes of type ID are searched.

Remember that a limitation of the XML ID datatype is that a single set of names across all attributes is declared to be of type ID. The XSLT key() function and the associated <xsl:key> element address this and other limitations; see the key() function and <xsl:key> for more information.

Output

A node-set containing all nodes whose attributes of type ID match the string values of the input node-set. In practice, this node-set is a single node, the node whose attribute of type ID matches a string value.

Defined in

XPath section 4.1, Node Set Functions.

Example

For our example, we’ll take this shortened version of the glossary we discussed earlier:

<?xml version="1.0" ?> <!DOCTYPE glossary SYSTEM "glossary.dtd"> <glossary> <glentry> <term id="applet">applet</term> <defn> An application program, written in the Java programming language, that can be retrieved from a web server and executed by a web browser. A reference to an applet appears in the markup for a web page, in the same way that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required