Simple location contexts

Typically, an element that has a significant context is identified simply by its location within the document structure. The name of the parent element, or some other ancestor element, determines the context.

Specific parent

In many cases, it is sufficient to specify what the parent element must be for the template to be applicable. In the following example, an X element is only to be selected when it is directly within a P element:

match="P/X"

The '/' symbol does not itself indicate that 'X' is the child of 'P'. This symbol is simply used to separate steps in a location path. When a particular step consists of only an element name, this is an abbreviation for the explicit statement 'child::X'. The following example is equivalent to the one above:

						child::P/child::X

Note that the first occurence of 'child::' above is doubly redundant, as there is no requirement for 'P' to be the child of some other element (for it could be the document's root element).

Using this technique, specific formatting could be applied to paragraphs within a Warning element:

   <para>A normal paragraph.</para>
   <warning>
     <para>Warning paragraph one.</para>
						<para>Warning paragraph two.</para>
   </warning>
   <para>Another normal paragraph.</para>


match="warning/para"

Specific ancestors

Sometimes, knowledge of the parent of an element is not sufficient. The element containing the parent element may be significant, or an element at an even higher level in the hierarchy. To select an element that is the descendant of specific ancestors, more elements are named in the expression:

match="A/P/X"

This example makes it more clear that the pattern is read from left to right, and also that the verbose equivalent is in fact very verbose in comparison:

match="child::A/child::P/child::X"

Using this technique, specific formatting could be applied to a warning paragraph that appears within the introduction of a book:

   <intro>
     <para>An introduction paragraph.</para>
     <warning>
       <para>Introduction Warning.</para>
     </warning>
   </intro>

match="intro/warning/para"

An introduction paragraph

Unknown ancestry

When several different elements could appear at a specific level, it would seem necessary to use several patterns, as in the following example, where paragraphs are to be formatted in a distinctive way within warnings, notes and errors, when these constructs appear within the Intro element:

match="intro/warning/para"


match="intro/note/para"


match="intro/error/para"

The need for three patterns can be avoided using a 'wildcard' that represents any element. The previous three expressions can be replaced by a single expression, using the asterisk character, '*', for the wildcard:

match="intro/*/para"

However, although the wildcard can be used repeatedly in the same pattern, this technique is quite limited because it is still necessary to know exactly how many levels deep the target element is. It would not be possible to identify a target element that appears at any point below another element without a large number of expressions:

match="intro/para"


match="intro/*/para"


match="intro/*/*/para"


match="intro/*/*/*/para"

To avoid this problem, it is possible to specify an unknown number of intermediate elements (including none). This is done using a double-slash, '//', as in the following example, which replaces the four above:

match="intro//para"

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset