- Predicates
- Functions in the [] square brackets
- = (EQUALS)
- element=
- child::chapter[child::chapterAuthor="Andrew Watt"] (This
one is looking for an element named "chapterAuthor", not an
attribute)
- attribute=
- child::chapter[attribute::title="XPATH"]
- =first()
- =last()
- !- (NOT EQUAL)
- and
- element
- child::*[self::chapter and self::appendix](This will choose the <chapter>
and <appendix> element children of our context node, whichever
shows up first
- attribute
- chapter[@number and @title] (selects only <chapter> children
of the context node that have both a number attribute and a title attribute)
- or (OR | )
- child::*[self::chapter or self::appendix][position()=last()] (This will
choose either the <chapter> or <appendix> element children
of our context node, whichever shows up first
- position() is the default function
- Unabbreviated functions (just the number listed):
- child::paragraph[position()=1]
- child::paragraph[position()=last()>1]
- child::chapter[position()=3][attribute::number] (choose the third
<chapter> element that is a child of our context node. If it has
an attribute named number, we will use it).
- Abbreviated functions (just the number listed):
- paragraph[1] (gets the first <paragraph> child element of the
context node)
- /book/chapters/chapter[2][@security='confidential'] (selects the fourth
<paragraph> child of the context node if it has a security attribute
equal to "confidential"
- /book/chapters/chapter/section[1]/paragraph[3] (selects the third
child <paragraph> element of the first <section> element
node that is a child of the <chapter> element)
- NodeTests
- position()
- default nodetest
- //paragraph[1] (selects all descendant <paragraph> elements
that are the first <paragraph> children of their parents)
- *
- * (selects all element nodes that are children of the context node)
- */paragraph (gets all grandchildren <paragraph> element nodes
of the context node) (equivalent to child::*/child::paragraph)
- node()
- /child::node() also gets the comment node
- text()
- text() (selects the text node of the context node)
- count()
- name()
- returns name of the node, if applied to a node-set, node parameter can
identify the node reequired. If more than one matches, you need a loop
- substring-after (.,' ')
- returns the next word after the first space