Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Song
001
And suddenly the wind comes soft,
002
And Spring is here again;
003
And the hawthorn quickens with buds of green
004
And my heart with buds of pain.
All the template rules defined in
standard-style.xsl
are used as normal, except where the current node matches the pattern
line
. In this situation there are two possible templates that match the node, so the one with higher import precedence is chosen. This is the one in the importing stylesheet module, namely
numbered-style.xsl
. As a result, the lines of the poem are output with a preceding line number, calculated using the
standard-style.xsl
stylesheet.
This use of
customization layer
. Another term used is
stylesheet overlay
. Sometimes the customization layer corresponds directly to an additional module in the schema or DTD: For example, if the schema that you use for press releases is an extended version of the schema used for general company documents, then you will want to write a customization layer over the general-purpose stylesheet to handle the additional features found in press releases.
See Also
xsl:import-schema
Changes in 2.0
This element is new in XSLT 2.0.
Format
namespace? = uri-reference
schema-location? = uri-reference>
If the
schema-location
attribute must be omitted.
Position
Attributes
Name | Value | Meaning |
namespace optional | URI | The namespace URI of the schema to be imported |
schema-location optional | URI | A URI identifying the location of the schema to be imported |
Content
The
Effect
If the stylesheet contains references to user-defined types, then the namespace in which these types are defined must be imported using an
Importing a schema makes the schema definitions available throughout the stylesheet, not only in the module where they are imported. (This differs from XQuery 1.0, where different modules may import different schemas.)
As with
The XSLT specification defines the way that schema import works in terms of the way that the XML Schema specification defines
schema-location
attribute is used is therefore very open-ended.
Although the terminology differs, this is not actually any different from the way the
href
attribute in
Using an inline schema document is exactly the same as putting the schema in a separate XML document and referencing it in the
schema-location
attribute. It's convenient to have the schema inline, however, if it contains definitions that are used only within this stylesheet, perhaps to define the structure of some working data or some constraints on a particular function parameter. If an
schema-location
attribute must be omitted. You can also omit the
namespace
attribute (if you don't, then it must match the
targetNamespace
of the inline schema).
In other cases, omitting the
namespace
attribute indicates that you want to import a schema that has no target namespace (that is, a schema for elements that are in no namespace). The
namespace
attribute should not be set to a zero-length string, since this is not a valid namespace URI.
If the
schema-location
attribute is omitted, and if there is no inline schema document, then it is assumed that the implementation will be able to locate a schema from knowledge of the target namespace alone.
It's not technically an error if no schema for the requested namespace can be found. But in practice this will usually trigger an error because the stylesheet will then contain references to schema definitions that haven't been imported.
It is a fatal error, however, if a schema can be found and it isn't valid according to the XML Schema specifications.
If there are multiple
Consistency rules for schemas extend beyond the question of multiple imports from a single stylesheet. The schema that's imported into the stylesheet must be consistent with the schema used to validate the source document. Since many systems will allow compiled schemas to be cached, probably sharing the cache between many different stylesheets, there is likely to be a more global consistency requirement. In general, it's probably not possible to have two different versions of the same schema (or to put it another way, two different schemas with the same target namespace, or with no target namespace) in use at the same time. Use of
If a processor that is not schema-aware encounters an
use-when=“system-property(‘xsl:schema-aware’)=‘yes’)”
to any element that should be ignored by a non-schema-aware processor (that is, the
type
or
validation
attribute, or references a schema-defined type). Of course, you will also have to provide an alternative element for use in this case.