Hi, I'm trying (and failing!) to learn XSLT and XPath and have a (hopefully) simple question I'm hoping someone could help with. Ok, here goes ..... Are all XPath expressions evaluated relative to an axis? For example, given the following template:

<template match="element()">..</template>

Is the implicit child axis included as part of the element() node test i.e. is the expression actually evaluated as child::element()?

Andy

From the XPath1.0 Recommendation

There are two kinds of location path: relative location paths and absolute location paths.

A relative location path consists of a sequence of one or more location steps separated by /. The steps in a relative location path are composed together from left to right. Each step in turn selects a set of nodes relative to a context node. An initial sequence of steps is composed together with a following step as follows. The initial sequence of steps selects a set of nodes relative to a context node. Each node in that set is used as a context node for the following step. The sets of nodes identified by that step are unioned together. The set of nodes identified by the composition of the steps is this union. For example, child::div/child::para selects the para element children of the div element children of the context node, or, in other words, the para element grandchildren that have div parents.

An absolute location path consists of / optionally followed by a relative location path. A / by itself selects the root node of the document containing the context node. If it is followed by a relative location path, then the location path selects the set of nodes that would be selected by the relative location path relative to the root node of the document containing the context node.

This article has been dead for over six months. Start a new discussion instead.