diff --git a/docs/topics/xpath-tutorial.rst b/docs/topics/xpath-tutorial.rst index 1a8e42d2d..936295384 100644 --- a/docs/topics/xpath-tutorial.rst +++ b/docs/topics/xpath-tutorial.rst @@ -1599,6 +1599,11 @@ This is what these axes select in our ASCII-tree representation: (``∪`` denoting the "union" for node-sets.) +Attribute axis +~~~~~~~~~~~~~~ + +TODO. + Node tests ---------- @@ -1656,6 +1661,39 @@ a node test can be: selected with ``self::*``) and recursively gets text content of children, children of children and so on. +Abbreviation cheatsheet +----------------------- + +.. list-table:: + :header-rows: 1 + + * - Abbreviated step + - Meaning + + * - ``*`` (asterisk) + - all **element** nodes (i.e. not text nodes, not attribute nodes). + + Remember that ``.//*`` is not the same as ``.//node()``. + + Also, there's no ``element()`` node test. + + * - ``@*`` + - ``attribute::*`` (all attribute nodes) + + * - ``//`` + - ``/descendant-or-self::node()/`` (exactly this, nothing more, nothing less) + + so ``//*`` is not the same as ``/descendant-or-self::*`` + + * - ``.`` (a single dot) + - ``self::node()``, the context node; useful for making XPaths relative, + e.g. ``.//tr`` + + * - ``..`` (2 dots) + - ``parent::node()`` + +TODO: explain why ``//*`` is not the same as ``/descendant-or-self::*`` + Predicates ---------- @@ -1689,13 +1727,11 @@ Positional predicates ~~~~~~~~~~~~~~~~~~~~~ The first use-case is selecting nodes based on their position in a -node-set. +node-set. (Node-sets order depends on the axis, but let's consider that +the order of a node in a node-set is the document order.) -Node-sets order depends on the axis, but let's consider that -the order of a node in a node-set is the document order. - -Let's say we don't want the two paragraphs in the ``
This is a paragraph.
' (2) 'Is this a link?
'] +Let's say that we are not interested in the two paragraphs but only +the first one. You would use ``[1]`` as predicate: + .. xpathdemo:: //body/div/div/p[1] @@ -1728,6 +1767,8 @@ earlier, only the first one: