XPath axes: me, my descendants, and my ancestors

short long means try it!
. self::node() me, whatever I happen to be (element, attribute, comment, processing instruction, document root, or even text) (note: long and short are not exactly equivalent) oXygen shows node cursor is in
said child::said my said children list all head elements for div children of the body
* child::* all my element children list all children of titleStmt
//div descendant::div my div descendants (note: long and short are not exactly equivalent) list all stage directions (stage)
.. parent::node() my parent, whatever it happens to be (element or root) list the parents of stage directions
[none] parent::author my parent, if it is an author list the speech (sp) parents of stage directions
[none] ancestor::div my div ancestors list all the headings of the div ancestors of the famous To be, or not to be (which you can find by searching for it)
[none] ancestor::* all my ancestors list the ancestors of the author element

This is a good cheat sheet for the different shorthands for writing in Xpath. We’ve already discussed the forward slash as shorthand for child, but now you can see that there are other ways of looking for different XPath axes (you don’t always want to be writing out descendant!). You can also try the queries in the far left column to try out different XPath searches.

XPath and Schematron for TEI Customization slide 14 of 24
© 2010 Syd Bauman and the Women Writers Project This TEI-encoded XML file is available under the terms of the Creative Commons Attribution-ShareAlike 3.0 (Unported) license.