Tutorial by Examples

Traversing from the root node to a descendant element using the child axis: /child::html/child::body/child::div/child::span Since the child axis is the default axis, this can be abbreviated to: /html/body/div/span
The descendant and descendant-or-self axes can be used to find all descendant elements of a node at any depth. In contrast, the child axis only traverses immediate children. /child::html/descendant::span /child::html/descendant-or-self::* The double slash // is a shortcut for /descendant-or-sel...
The parent axis contains only the parent of a node. The following expression selects the html element by taking a detour over the body element: /child::html/child::body/parent::html .. is a shortcut for parent::node() The ancestor and ancestor-or-self axes traverse all ancestors of a node. The ...
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::nod...
The following-sibling and preceding-sibling axes contain the siblings before or after the context node, and the following and preceding axes contain all nodes in the document before or after the context node, but: None of these axes contain attribute or namespace nodes. The following axis doesn'...
The attribute and namespace axes contain all attribute and namespace nodes of an element. The shortcut @ stands for attribute::, so the following are equivalent: child::div/attribute::class div/@class

Page 1 of 1