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

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
9.41Mb size Format: txt, pdf, ePub
xpath-default-namespace
optional
Namespace URI
Defines the namespace URI that is assumed for unprefixed element names and type names occurring in XPath expressions, patterns, and certain other constructs such as the SequenceType in an
as
attribute.

The attributes
default-collation
,
exclude-result-prefixes
,
extension-element-prefixes
,
version
,
use-when
, and
xpath-default-namespace
can be specified on any element in the XSLT namespace. They can also be used on literal result elements, though in this case the attribute must be in the XSLT namespace, to distinguish it from user-defined attributes that are to be copied to the result tree. Collectively these attributes are referred to by names such as
[xsl:]version
, since they are sometimes namespace-prefixed.

These attributes are described here because they are usually used on the

element. They are not included in the proforma of other XSLT elements in order to save space.

The
[xsl:]use-when
attribute is more likely to appear on elements in a stylesheet other than the

or

element. This attribute allows you to specify a compile-time conditional expression, and the element on which it appears will be included in the compiled stylesheet only if this condition is true. If the attribute is present on the

or

element and takes the value
false
, the effect is as if the stylesheet module contained no top-level declarations. This attribute is described on page 127.

In the case of
default-collation
,
version
and
xpath-default-namespace
, the effective value of the attribute for a particular instruction in the stylesheet is the value on the nearest enclosing element, or the instruction itself, that has a value for this attribute. In the case of
extension-element-prefixes
and
exclude-result-prefixes
, the values are cumulative—a namespace is an extension namespace or excluded namespace if it is listed as such on some enclosing instruction.

In practice the most useful place to specify these attributes is often on the

or

declarations, in which case they apply to the body of a template or function.

The sections below (starting with
The id Attribute
) consider each of the attributes in turn, describing first the formal rules for the attribute, then advice on usage and examples where appropriate.

Content

The

element may contain XSLT elements referred to as
top-level declarations
. These elements are:
















If there are any

elements, they must come before other top-level declarations.

The

element may also contain other elements provided they use a non-null namespace URI that is different from the XSLT namespace URI. If the namespace URI is recognized by the XSLT processor, it may interpret such elements in any way the vendor chooses, provided that the correct functioning of the stylesheet is not affected. If it does not recognize these elements, it should ignore them.

The id Attribute

This attribute allows an

element to be referenced when it is contained within another XML document.

Effect

The precise usage is not defined in the standard, but the expectation is that this
id
attribute will allow an embedded stylesheet to be referenced in an

processing instruction. An example is given in Chapter 3 on page 102. The specification points out that for this to work, it may be necessary for the
id
attribute to be declared in a DTD or schema as having the attribute type
ID
. However, not all XSLT processors impose this restriction.

Usage

If the XSLT processor you are using supports embedding of stylesheets within the source document that they are to transform, then the typical layout will be like this:



   

]>




   

      xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”

   >

   

   

   

   


Note that when this structure is used, the stylesheet will be presented with the entire source document, including a copy of itself. The stylesheet therefore needs to be written to handle its own elements in an appropriate way, hence the empty template rule that matches all elements in the XSLT namespace.

XSLT 2.0 defines the media type (MIME type)
application/xslt+xml
for XSLT stylesheet modules, but the unofficial usage
text/xsl
is much more widely supported in today's products.

The default-collation Attribute

This attribute can be used at the

level to define the default collation used for all XPath expressions within the stylesheet module. It does not affect included or imported modules. The attribute can also appear on any other XSLT element (or, prefixed as
xsl:default-collation
, on a literal result element) to define a default with more local scope.

Effect

Collations are discussed under

on page 459. However, collations are used not only when sorting but also whenever strings are compared. The default collation is used by operators such as
eq
,
lt
,
=
, or
<
, and by functions such as
min()
,
max()
,
distinct-values()
, and
index-of()
whenever no other collation is specified. As well as defining the collation used by these XPath operators and functions, the
[xsl:]default-collation
attribute also affects XSLT elements such

and

. One place that is not affected by this attribute, curiously, is

itself.

Other books

My American Unhappiness by Dean Bakopoulos
Under the Jaguar Sun by Italo Calvino
Hyde and Seek by Layla Frost
The Other Countess by Eve Edwards
Siege and Storm by Leigh Bardugo
Poder burgués y poder revolucionario by Mario Roberto Santucho
Within the Hollow Crown by Margaret Campbell Barnes
Ashes in the Wind by Kathleen E. Woodiwiss
Love LockDown by A.T. Smith