MENU
Path Expressions
| Basic Syntax | ||
| A | All <A> nodes within the current context, ie. relative to the current path. | |
| /A | The <A> root node, ie. an absolute path. | |
| //A | All <A> nodes in the document, regardless of how deeply nested they are. | |
| . | The current context, ie. the current node. | |
| .. | The parent context, ie. the parent node. | |
| A/B | All <B> nodes that are the direct children of <A> nodes within the current context. | |
| A//B | All <B> nodes that are the descendants of <A> nodes within the current context. | |
| A/* | All nodes that are the direct children of <A> nodes within the current context. | |
| @A | The ‘A’ attribute of the current context/node. (An attribute may be treated as the child of its node.) | |
| @* | All attributes of the current context/node. | |
| N:A | All <A> child nodes from the N namespace within the current context. | |
| N:* | All nodes from the N namespace within the current context. | |
| *:A | All <A> nodes from all namespaces within the current context. | |
| A[B] | All <A> nodes containing a <B> child node. | |
| A[@B] | All <A> nodes containing the attribute B. | |
| A/@B | All B attributes in <A> within the current context. | |
| A[3] | The third <A> node within the current context. | |
| A[B][3] | The third <A> node containing a <B> child within the current context. | |
| (A/B)[3] | The third <B> node that is a child of an <A> node within the current context. | |
| A/text()[2] | The second text node in each <A> node within the current context. | |
| A|B | All <A> and <B> child nodes within the current context. | |
| The square brackets [] at the right can assume a Boolean value, an integer, or a node. A complex Boolean expression joined by and/or can be formed out of the three types of values. | ||
| Axes | ||
| child::* | * matches only element nodes. If node() is used instead, text, comment and processing instruction nodes are matched as well. Multiple nodes may be returned. For example, preceding-sibling::node()[2] returns the previous node that is two siblings away. Any derived types of node() can be used in place of node(), eg. child::comment(). |
|
| descendant::* | ||
| descendant-or-self::* | ||
| self::* | ||
| following::* | ||
| following-sibling::* | ||
| ancestor::* | ||
| ancestor-or-self::* | ||
| parent::* | ||
| preceding::* | ||
| preceding-sibling::* | ||
| namespace::* | ||
| attribute::* | ||
| Complex Filters | ||
| A[position()<3] | The first two <A> nodes. | |
| A[last()] | The last <A> child node. | |
| A[B][C] | All <A> nodes containing a <B> node and a <C> node. | |
| A[(B or C) and D] | All <A> nodes containing a <D> node, and a <B> node or a <C> node. | |
| A[not(B)] | All <A> nodes which do not contain a <B> node. | |
| A[B=”C”] | All <A> nodes containing the <B> nodes with the value C. | |
| A[.!=”B”] | All <A> nodes with a value that is not “B”. | |
| (B|C) [@at eq A/@at] | All <B> nodes and <C> nodes with the attribute @at equals that of <A>. | |
| Examples |
| <?xml version="1.0"?> <menu restaurant="Golden Outlet"> <dish id="1">Satay <i>Cooked</i></dish> <drink id="2">Cola</drink> <dish id="3">Curry Chicken</dish> <dish id="4" xmlns="http://example.com"> Sweet and Sour Pork </dish> </menu> |
GIVE <?xml version="1.0"?> <menu restaurant="Golden Outlet"> <dish id="1">Satay <i>Cooked</i></dish> <drink id="2">Cola</drink> <dish id="3">Curry Chicken</dish> <dish id="4" xmlns="http://example.com"> Sweet and Sour Pork </dish> </menu> |
(11) menu[last()]|menu[position()=1]|menu[1] (12) if (//dish) then menu else //dish GIVE <menu restaurant="Golden Outlet"> <dish id="1">Satay <i>Cooked</i></dish> <drink id="2">Cola</drink> <dish id="3">Curry Chicken</dish> <dish id="4" xmlns="http://example.com"> Sweet and Sour Pork </dish> </menu> |
restaurant="Golden Outlet" |
(11)menu/child::node()[@id!=2 and not(@id=4)] (12)menu/dish[i]|menu/dish[.="Curry Chicken"] (13)/menu/element(dish) GIVE (1) <dish id="1">Satay <i>Cooked</i></dish> (2) <dish id="3">Curry Chicken</dish> |
Cooked |
|
true |
|