Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
, the leading
.
becomes necessary to indicate that you want to start the selection at the context node, not at the root document node.
Expressions using
//
can be expensive to evaluate, because the XPath processor will often have to search the whole document to find the selected nodes. If you can specify a more restricted search, it is generally a good idea to do so—for example, if you know that all the
/*/book
will generally be much more efficient than writing
//book
. Of course, actual performance characteristics of different products may vary. In some XML database products, elements are indexed in such a way that
//book
becomes very fast.
Examples Using
//
Expression | Description |
//figure | Selects all elements in the document. |
//book[@category = ‘fiction’] | Selects all category attribute with the value fiction . |
//*/* | Selects all element nodes that have an element as a parent, in other words all elements except those that are immediate children of the root node. Here * is a NameTest that matches any element. |
//book/title | Selects all |
chapter//footnote | Selects all |
.//footnote | Selects all |
doc(‘lookup.xml’)//entry | Selects all lookup.xml . The doc() function is described in Chapter 13, page 750. |
$winners//*/@name | Selects the name attribute of all elements that are descendants of a node that belongs to the node-set identified by the variable $winners . |
.//. . | This strange but perfectly legal expression combines // , which finds the descendants of a node, and .. , which finds its parent. The effect is to find all nodes that are the parent of a descendant of the context node, plus the parent of the context node itself. |
chapter//footnote | Selects all |