This file is indexed.

/usr/share/doc/python-genshi-doc/txt/xpath.txt is in python-genshi-doc 0.7-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
.. -*- mode: rst; encoding: utf-8 -*-

=====================
Using XPath in Genshi
=====================

Genshi provides basic XPath_ support for matching and querying event streams.

.. _xpath: http://www.w3.org/TR/xpath


.. contents:: Contents
   :depth: 2
.. sectnum::


-----------
Limitations
-----------

Due to the streaming nature of the processing model, Genshi uses only a subset
of the `XPath 1.0`_ language.

.. _`XPath 1.0`: http://www.w3.org/TR/xpath

In particular, only the following axes are supported:

* ``attribute``
* ``child``
* ``descendant``
* ``descendant-or-self``
* ``self``

This means you can't use the ``parent``, ancestor, or sibling axes in Genshi
(the ``namespace`` axis isn't supported either, but what you'd ever need that
for I don't know). Basically, any path expression that would require buffering
of the stream is not supported.

Predicates are of course supported, but path expressions *inside* predicates
are restricted to attribute lookups (again due to the lack of buffering).

Most of the XPath functions and operators are supported, however they
(currently) only work inside predicates. The following functions are **not**
supported:

* ``count()``
* ``id()``
* ``lang()``
* ``last()``
* ``position()``
* ``string()``
* ``sum()``

The mathematical operators (``+``, ``-``, ``*``, ``div``, and ``mod``) are not
yet supported, whereas sub-expressions and the various comparison and logical
operators should work as expected.

You can also use XPath variable references (``$var``) inside predicates.


----------------
Querying Streams
----------------

The ``Stream`` class provides a ``select(path)`` function that can be used to
retrieve subsets of the stream:

.. code-block:: pycon

  >>> from genshi.input import XML

  >>> doc = XML('''<doc>
  ...  <items count="4">
  ...       <item status="new">
  ...         <summary>Foo</summary>
  ...       </item>
  ...       <item status="closed">
  ...         <summary>Bar</summary>
  ...       </item>
  ...       <item status="closed" resolution="invalid">
  ...         <summary>Baz</summary>
  ...       </item>
  ...       <item status="closed" resolution="fixed">
  ...         <summary>Waz</summary>
  ...       </item>
  ...   </items>
  ... </doc>''')

  >>> print(doc.select('items/item[@status="closed" and '
  ...     '(@resolution="invalid" or not(@resolution))]/summary/text()'))
  BarBaz



---------------------
Matching in Templates
---------------------

See the directive ``py:match`` in the `XML Template Language Specification`_.

.. _`XML Template Language Specification`: xml-templates.html