Although you can't make a runtime decision on what modules to import or include, you can use compile-time conditional logic. For example, you can write:
use-when = “system-property(‘xsl:vendor’) = ‘Altova GmbH’”/>.
This allows conditional inclusion of a module based on information that is known at compile time. There is more information on the
use-when
attribute later in the chapter: see the section “Writing Portable Stylesheets” on page 127.
The Element
The
element (or
, which is a synonym) is the outermost element of every stylesheet module.
The name
is a conventional name. The first part,
xsl
, is a prefix that identifies the namespace to which the element name belongs. Any prefix can be used so long as it is mapped, using a namespace declaration, to the URI
http://www.w3.org/1999/XSL/Transform
. There is also a mandatory
version
attribute. So the start tag of the
element will usually look like this:
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”
version=“2.0”
>
The
element can also be written as
if you prefer to think of XSLT as doing transformations rather than styling. The two names are completely interchangeable, but I usually use
for familiarity. Everything I say about the
element applies equally to
.
As a general principle, it's advisable to specify
version = “2.0”
if the stylesheet module uses any facilities from XSLT 2.0 or XPath 2.0, and
version = “1.0”
if it relies only on XSLT 1.0 and XPath 1.0 features. This isn't purely documentary; as we'll see later (see page 128), XSLT processors have some subtle differences in behavior, depending on the setting of this attribute.
If you encounter a stylesheet that uses the namespace URI
http://www.w3.org/TR/WD-xsl
, then the stylesheet is written in a Microsoft dialect based on an early working draft of the XSLT 1.0 standard. There are many differences between this dialect and XSLT 1.0, and even more differences between WD-xsl and XSLT 2.0. Although it has been obsolete for some years, you may still come across it occasionally.
The other attributes that may appear on this element are described under
in Chapter 6, page 465. Specifically, they are as follows:
- id
identifies the stylesheet when it appears as an embedded stylesheet within another document. Embedded stylesheets are described in the next section.
- extension-element-prefixes
is a list of namespace prefixes that denote elements used for vendor-defined or user-defined extensions to the XSLT language.
- exclude-result-prefixes
is a list of namespaces used in the stylesheet that should not be copied to the result tree unless they are actually needed. I'll explain how this works in the section
Literal Result Elements
on page 112.
- xpath-default-namespace
is a namespace URI, which is used as the default namespace for unprefixed element names used in path expressions within the stylesheet, and also for unprefixed type names. This attribute is handy when all the elements in your source document are in a particular namespace, because it saves you having to use a namespace prefix every time you refer to an element in this namespace. Without this attribute, element names with no prefix are assumed to refer to names in the null namespace (neither the default namespace declared using
xmlns = “uri”
in the stylesheet, nor the default namespace declared in the source document, has any effect on names used in path expressions).
- default-validation
takes one of the values
preserve
or
strip
. This attribute is used by a schema-aware processor to determine whether any schema-derived type annotations are retained when elements and attributes are copied. You will find more details of how result trees are validated against a schema in Chapter 4.
- default-collation
defines how strings are to be compared and sorted. There are many different conventions for sorting strings, depending on the language and sometimes on the whims of a publisher. The value of this attribute is simply a URI that acts as a name for the set of conventions to be used; the values you can use for this attribute will vary from one XSLT processor to another. For more details on collations, see
on page 459 in Chapter 6.
- input-type-annotations
takes one of the values
preserve
,
strip
,
or
unspecified
. This attribute is used by a schema-aware processor to determine whether any schema-derived type annotations are retained in the input document.