XPath Abbreviated Syntax

You can take advantage of a number of abbreviations in XPath syntax. Here are the rules:

  • self::node()can be abbreviated as .

  • parent::node()can be abbreviated as ..

  • child::childname can be abbreviated as childname

  • attribute::childname can be abbreviated as @childname

  • /descendant-or-self::node()/can be abbreviated as //

For example, the location path .//PLANET is short for self::node()/descendant-or-self::node()/child::PLANET. You can also abbreviate the predicate expression [position() = 3] as [3], [position() = last()] as [last()], and so on. Using the abbreviated syntax makes XPath location paths a lot easier to use. The following list includes some examples of location paths that use abbreviated syntax:

  • PLANET returns ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.