XPath Axes
Estimated study time: 12 minutes.
An axis in XPath defines the direction you move through the document tree relative to a starting node — not just downward to children, but upward to ancestors, sideways to siblings, and more.
Common Axes
child::module <!-- direct children named module -->
parent::course <!-- the parent node -->
ancestor::course <!-- all ancestor nodes named course -->
descendant::module <!-- all descendants, any depth, named module -->
following-sibling::module <!-- sibling nodes that come after this one -->
preceding-sibling::module <!-- sibling nodes that come before this one -->
self::course <!-- the current node itself -->
Shorthand You Already Know
Many everyday XPath expressions are actually shorthand for the child and descendant axes:
moduleis shorthand forchild::module//moduleis shorthand fordescendant-or-self::node()/child::module@idis shorthand forattribute::id
Practical Example
//module[text()='SQL for Analysis']/following-sibling::module
This finds the module named "SQL for Analysis," then selects whichever module elements come after it as siblings.
💡 Tip: You'll use the child and descendant axes most of the time via shorthand — reach for the explicit axis names like
ancestor:: or following-sibling:: only when you need to move up or sideways in the tree.