XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (180 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
5.06Mb size Format: txt, pdf, ePub

If one stylesheet module incorporates another using

rather than

, it has the same import precedence as the module that includes it (see
Figure 6-4
).

Here J is included in E, so it has the same import precedence as E, and similarly E has the same import precedence as C.

The import precedence of a stylesheet module applies to all the declarations in that module, so for example the

elements in module E have a higher import precedence than those in G.

As

statements must occur before any other declarations in a stylesheet module, the effect of these rules is that if each

statement were to be replaced by the content of the module it imports, the declarations in the resulting combined stylesheet would be in increasing order of import precedence. This makes life rather easier for implementors. However, it does not mean that

is a straightforward textual substitution process, because there is still a need to distinguish cases where two objects (for example template rules) have the same import precedence because they came originally from the same stylesheet or from stylesheets that were included rather than imported.

The XSLT 2.0 specification introduces the concept of a
stylesheet layer
, which is a group of stylesheet modules that have the same import precedence because they refer to each other using

rather than

. In the example above modules D and G are in the same layer; C, E, and J are in the same layer, and each of the other modules is in a layer of its own. Within a stylesheet layer the specification describes the concept of
declaration order
, which is the order that the declarations (top-level elements) would appear in if included stylesheets were expanded at the point of the

statement. The stylesheet layers (rather than modules) are considered to form a tree, with

elements acting as the links from a parent to a child in the tree.

The stylesheet tree for the example above is shown in
Figure 6-5
.

The concepts of stylesheet levels, declaration order, and the stylesheet tree have been used to tighten up the specification of how instructions such as

work. For example, an

instruction in module J can invoke a template in module H, because H is in a stylesheet layer that is a descendant of the layer that J is in.

Effect of Import Precedence

The import precedence of a declaration affects its standing relative to other declarations of the same type, and may be used to resolve conflicts. The effect is as shown in the table below for each kind of declaration.

Element type
Rules

If there are two attribute sets with the same expanded name, they are merged. If there is an attribute that is present in both, then the one from the attribute set with higher import precedence wins. If there are two or more values for an attribute that have the same precedence, and this is the highest precedence, the XSLT processor chooses the one that was specified last (for a more precise definition of what “last” means, see

on page 266).

If there are several

declarations with the same name, then the one with highest import precedence wins. It is an error if this leaves no clear winner.

All the

elements in the stylesheet that share the same name are effectively merged. For each attribute, if the value is explicitly present on more than one

element, then the one with highest import precedence wins. It is an error if there is no clear winner.

If there are several

declarations with the same name and arity (number of arguments), then the one with highest import precedence wins. It is an error if this leaves no clear winner.


No conflicts arise; the import precedence of these elements is immaterial, except in determining the import precedence of the referenced stylesheet module.

If there are several

declarations for the same target namespace (or for no target namespace) then the one with highest import precedence wins. If this leaves more than one, then the rules are defined by reference to the XML Schema specifications, which give implementations a great deal of latitude.

All the key definitions are used, regardless of their import precedence. See

on page 376 for details.

If several aliases for the same stylesheet prefix are defined, the one with the highest import precedence is used. It is an error if there is no clear winner.

All the

elements in the stylesheet that share the same name are effectively merged. In the case of the
cdata-section-elements
and
use-character-maps
attributes, the values from all the

elements are merged. For all the other attributes, if the value is explicitly present on more than one

element, then the one with highest import precedence wins. It is an error if there is no clear winner.


If there is more than one

or

element that matches a particular element name in the source document, then the one with highest import precedence is used. If this still leaves several that match, each one is assigned a priority, using the same rules as for the
match
pattern in

. Specifically, an explicit
QName
has higher priority than the form
prefix:*
, which in turn has higher priority than
*
. The one with highest priority is then used.
It is an error if this leaves more than one match, unless they all give the same answer.

When selecting a template rule for use with

, firstly all the template rules with a matching
mode
are taken. Of these, all those with a
match
pattern that matches the selected node are considered. If this leaves more than one, only those with the highest import precedence are considered. If this still leaves more than one, the one with highest priority is chosen: The rules for deciding the priority are given under

on page 483. It is an error if this still doesn't identify a clear winner. The XSLT processor has the choice of reporting the error or choosing the template rule that was specified last. (In practice, several processors output a warning message).
In the case of named templates, if there are several

declarations with the same
name
attribute, then the one with highest import precedence wins. It is an error if this leaves no clear winner.


If there are several global

or

declarations with the same name, then the one with highest import precedence wins. It is an error if this leaves no clear winner.

Other books

This Totally Bites! by Ruth Ames
Shake the Trees by Rod Helmers
Death Comes Silently by Carolyn Hart
Rules to Rock By by Josh Farrar
Blood by Fox, Stephen
Sexing the Cherry by Jeanette Winterson