The self
axis only contains the context node itself. The expression .
is a shortcut for self::node()
and always matches the context node. The .
shortcut is useful for enumerating descendants of the context node. The following expressions are equivalent:
.//span
self::node()/descendant-or-self::node()/child::span
descendant::span
The self
axis can be helpful in XPath 1.0 predicates. For example, to select all h1
, h2
, and h3
children of the context node:
*[self::h1 or self::h2 or self::h3]