Share via


Location Paths

A ___location path is an XPath expression used for selecting a set of nodes relative to the context node. The evaluation of a ___location path expression results in a node-set containing the nodes specified by the ___location path. A ___location path can recursively contain expressions used to filter sets of nodes.

Syntactically, a ___location path consists of one or more ___location steps, each separated by a forward slash (/):

locationstep/locationstep/locationstep

Each ___location step in turn selects a set of nodes relative to the context node — that is, to the node selected by the preceding ___location step. A ___location path expressed this way is a relative ___location path. An absolute ___location path starts from the root element:

/locationstep/locationstep/locationstep

In a ___location path, ___location steps are evaluated from left to right. The leftmost ___location step selects a set of nodes relative to the context node. These nodes then become the context used to process the next ___location step. This processing of steps and updating of the context node repeats itself until all the ___location steps have been processed.

A ___location path can be unabbreviated or abbreviated.

In an unabbreviated ___location path, a ___location step has the following syntax:

axis::node-test[predicate]

In this syntax, axis specifies how the nodes selected by the ___location step are related to the context node; node-test specifies the node type and expanded name of the nodes selected by the ___location step; and predicate is a filter expression to further refine the selection of nodes in the ___location step. Predicates are optional. In this case, a ___location step consists of axis:: and node-test only. The following table provides some examples.

Unabbreviated Location Path Description

child::para[last()]

Selects the last <para> element of the context node.

parent::para

Selects the <para> element that is the parent of the context node.

child::text()

Selects all text node children of the context node.

child::div/child::para

Selects the <para> child elements of the <div> element that is a child of the context node.

In an abbreviated ___location path, the axis specifier, axis::, is not expressed explicitly in a ___location step, but implied by a set of shot cuts instead. The following table provides some examples.


Abbreviated Location Path Description

para

Selects the <para> elements of the context node.

../para

Selects the <para> element that is the parent of the context node.

text()

Selects all text node children of the context node.

./div/para

Selects the <para> element children of the <div> element children of the context node.

The following is a summary of some of the abbreviations:

Unabbreviated Abbreviated

child::*

*

attribute::*

@*

/descendant-or-self::node()

//

self::node()

.

parent::node()

..

In This Section

The following topics discuss in detail the syntax and usage of the pieces of ___location paths.