comparison doc/xpath.txt @ 820:1837f39efd6f experimental-inline

Sync (old) experimental inline branch with trunk@1027.
author cmlenz
date Wed, 11 Mar 2009 17:51:06 +0000
parents 55cf81951686
children 09cc3627654c
comparison
equal deleted inserted replaced
500:0742f421caba 820:1837f39efd6f
50 * ``position()`` 50 * ``position()``
51 * ``string()`` 51 * ``string()``
52 * ``sum()`` 52 * ``sum()``
53 53
54 The mathematical operators (``+``, ``-``, ``*``, ``div``, and ``mod``) are not 54 The mathematical operators (``+``, ``-``, ``*``, ``div``, and ``mod``) are not
55 yet supported, whereas the various comparison and logical operators should work 55 yet supported, whereas sub-expressions and the various comparison and logical
56 as expected. 56 operators should work as expected.
57 57
58 You can also use XPath variable references (``$var``) inside predicates. 58 You can also use XPath variable references (``$var``) inside predicates.
59 59
60 60
61 ---------------- 61 ----------------
62 Querying Streams 62 Querying Streams
63 ---------------- 63 ----------------
64 64
65 :: 65 The ``Stream`` class provides a ``select(path)`` function that can be used to
66 retrieve subsets of the stream:
66 67
67 from genshi.input import XML 68 .. code-block:: pycon
68 69
69 doc = XML('''<doc> 70 >>> from genshi.input import XML
70 <items count="2">
71 <item status="new">
72 <summary>Foo</summary>
73 </item>
74 <item status="closed">
75 <summary>Bar</summary>
76 </item>
77 </items>
78 </doc>''')
79 print doc.select('items/item[@status="closed"]/summary/text()')
80 71
81 This would result in the following output:: 72 >>> doc = XML('''<doc>
73 ... <items count="4">
74 ... <item status="new">
75 ... <summary>Foo</summary>
76 ... </item>
77 ... <item status="closed">
78 ... <summary>Bar</summary>
79 ... </item>
80 ... <item status="closed" resolution="invalid">
81 ... <summary>Baz</summary>
82 ... </item>
83 ... <item status="closed" resolution="fixed">
84 ... <summary>Waz</summary>
85 ... </item>
86 ... </items>
87 ... </doc>''')
82 88
83 Bar 89 >>> print doc.select('items/item[@status="closed" and '
90 ... '(@resolution="invalid" or not(@resolution))]/summary/text()')
91 BarBaz
92
84 93
85 94
86 --------------------- 95 ---------------------
87 Matching in Templates 96 Matching in Templates
88 --------------------- 97 ---------------------
Copyright (C) 2012-2017 Edgewall Software