XML technologies / XSLT / Reference: XSLT 1.0 and 2.0 elements / import-schema
(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 6.)
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z
Use top-level element xsl:import-schema to make XML Schema definitions needed for stylesheet processing statically available. A schema-aware XSLT processor is required.
Classification | Declaration |
Function group | Importing schema data types |
Introduction | XSLT 2.0 |
Position in the stylesheet and permitted contents:
xsl:import-schema is top-level, occurring only as an immediate child of root elements xsl:stylesheet or xsl:transform.
The element may optionally contain a schema declaration <xs:schema>. In that case, attribute schema-location must be omitted.
Attributes:
Standard attributes apply. Declaration xsl:import-schema also has two optional alternative attributes namespace and schema-location. One should normally be supplied.
namespace
Value | uri-reference |
Usage | Optional |
Introduction | XSLT 2.0 |
The namespace attribute identifies the namespace URI used by the imported definitions. The empty string is forbidden because it is not a valid namespace URI.
Note: The namespace attribute of xsl:import-schema does not simultaneously declare that namespace for the stylesheet! A separate namespace declaration is required on root element xsl:stylesheet.
schema-location
Value | uri-reference |
Usage | Optional |
Introduction | XSLT 2.0 |
The schema-location attribute holds a URI string giving the relative or absolute address of an XML Schema document containing the definitions to import. It is an alternative to declaration content.
Note: If attribute schema-location is supplied while the declaration contains a schema definition <xs:schema>, this is a static error (ERR XTSE0215).
Purpose:
The xsl:import-schema declaration imports schema components, including type definitions and top-level element or attribute declarations, from an external XML Schema file into the static context.
It is also required when checking a stylesheet as it is read, before processing a source document, needs external schema definitions. Importing them permits static checks even when a source document with an associated schema is not yet available.
Only a schema-aware XSLT processor can process this instruction.
Imported user-defined types are available in every module alongside predefined XML Schema and XPath 2.0 types (built-in types), and can be used in conversions, including explicit casts to user-defined types.
Imported element and attribute declarations enter the static context and are available in all modules for sequence-type expressions in type or as attributes of corresponding instructions.
Schema files or definitions are located using URI strings in attribute schema-location or alternatively namespace. This can identify an external document directly through its URI or the targetNamespace attribute on root element xsd:schema, or definitions in a local repository accessible to the application.
If both attributes are used, the identified document must also be valid for the specified namespace:
Schema document beispiel.xsd
<xsd:schema targetNamespace="http://beispielnamensraum" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="test" type="xsd:string"/>
</xsd:schema>
could be located as follows:
<xsl:import-schema schema-location="beispiel.xsd" namespace="http://beispielnamensraum"/>
or with either location attribute alone:
<xsl:import-schema schema-location="beispiel.xsd"/>
<xsl:import-schema namespace="http://beispielnamensraum"/>
The exact lookup procedure is unspecified and implementation-dependent.
If the XSLT processor cannot use the information in attributes namespace and schema-location to locate the schema, or the resource is invalid or unusable because of ambiguous definitions, a static error occurs and the stylesheet cannot be processed.
Element definition:
XSLT 1.0:
Element unavailable in XSLT 1.0.
XSLT 2.0:
<!-- Category: declaration -->
<xsl:import-schema
namespace? = uri-reference
schema-location? = uri-reference>
<!-- Content: xs:schema? -->
</xsl:import-schema>
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from “XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn