Compartilhar 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.