Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
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
The
[xsl:]use-when
attribute is more likely to appear on elements in a stylesheet other than the
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
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
top-level declarations
. These elements are:
If there are any
The
The id Attribute
This attribute allows an
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
xsl:default-collation
, on a literal result element) to define a default with more local scope.
Effect
Collations are discussed under
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