24.3. ID function The most common high-level expression in XPath is the location path, which we have explored in some detail. And, as we have seen, a location path can also be used at lower levels - as a predicate expression, for example. Another form of expression that returns a node-set is a function call to the id(string) function. The main use of the function is to select the element node whose ID is the same as the string. For example, "id('final')". selects the element node whose unique identifier is "final". An ID function and a location path can be used in the same expression. One way is to create the union of the two, as in Example 24-7. The result node-set is the element whose ID is "final", plus all para elements descended from ordered-list elements. Example 24-7. Union expression id('final') | /ordered-list//para Another way to combine the two is to use the ID function as the initial context node of a location path, to create a path expression like that in Example 24-8. It locates the title child of the element whose ID is "A12345". Example 24-8. Path expression id('A12345')/title Instead of a literal string, the argument could be a node whose string-value would be used, as in "id(@IDREF)". This expression locates the element referenced by the IDREF attribute of the context node. |