XPath Syntax Quick Reference

This topic provides a quick reference for XPath expression syntax.

Axes

XPath provides the following axes:

l ancestor
l ancestor-or-self
l attribute
l child
l descendant
l descendant-or-self
l following
l following-sibling
l namespace
l parent
l preceding
l preceding-sibling
l self

Node Tests

XPath provides the following node tests:

l * selects all nodes of the specified name. For the attribute axis, attributes are selected. For the namespace axis, namespace nodes are selected. For all other axes, element nodes are selected.
l comment() selects all comment nodes.
l element_name selects all element_name nodes.
l node() selects all nodes.
l processing-instruction(["some_literal"]) selects all processing instructions. If some_literal is specified, processing-instruction() selects all processing instructions with some_literal as their name.
l text() selects all text nodes.

Filters

A filter specifies a constraint on a node set with respect to an axis to produce a new node set.

Location Steps

A location step has the following format:

XPath Expression

An XPath expression has one of the following formats:

A function call or an XPath expression in parentheses can appear only at the very beginning of an XPath expression. An expression in parentheses always returns a node set. Any function that appears at the beginning of an XPath location step expression must return a node set.

 
Free Stylus Studio XML Training:
W3C Member