Click to return to the XML (Extensible Markup Language) home page    
context Method     Context Changing Operator...    
Web Workshop  |  XML (Extensible Markup Language)

id Method


Returns the element or elements referenced by the specified ID.

Syntax

id(expression)

Parameters

expression
Specifies either an XSL Pattern, such as id(a/b/@c), or a quoted constant indicating the literal ID values to be matched, such as id("1 2").

Remarks

XSL Patterns supports a syntax for traversing links based on links and link targets, which in turn are based on IDs. Links are specified by providing a space-separated list of IDs. Because IDs specify the link targets, they must be unique across the document.

IDs must be declared in a document type definition (DTD) or schema. XSL does not enforce references to IDs to be declared as IDREFs.

An expression can follow the links by using the id method for indirection. In this case the argument is an XSL pattern instead of a literal string, and the id method can be placed on the right of / or // operators. For example, consider the following XML source:

<root>
  <a id="1">
    <b>Hello</b>
  </a>
  <c link="1"/>
</root>

The expression root/c/id(@link)/b returns the b node. root/c/id(@link) returns the a node; id(@link) refers to the element whose ID is equal to the value 1.

When there are multiple IDs in a link, the id method returns the set of referenced nodes. Consider the following example:

<root>
  <a id="1">
    <b>Hello</b>
  </a>
  <a id="2">
    <b>Good bye</b>
  </a>
  <c link="1 2"/>
</root>

The expression root/c/id(@link)/b returns the two b nodes, one from each of the a nodes that are referenced. This expression is equivalent to the expression id(root/c/@link)/b.

The id method can take any XSL pattern as an expression. Thus, it can also operate on element values. Using the same source as the previous example, the expression root/id(c)/b returns two b nodes, one from each of the nodes.

The id method can take either an XSL Pattern expression or a quoted constant, such as id("1 2"). Note that you cannot use a quoted constant parameter to the id method when it appears in an XSL Pattern to the right of a /.

When an invalid ID constant is supplied, the id method returns null.

The following two XSL patterns are equivalent:

/studentlist/student/id(@attends)
id(/studentlist/student/@attends)

Because links are explicitly followed using a keyword, there is no need to check for circular linking.

Note that the id method can be used with the union operator, as follows: A union can be passed as the argument to the id method. For information about constraints on the interaction of the id method and unions, see the reference documentation for the Set Operations.



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.