Identifies schema components (top-level type definitions and top-level element and attribute declarations) that need to be available statically, that is, before any source document is available. Allows you to extend XSLT built-in types with the types defined in the imported XML Schema.


  namespace = uri-reference 
  schema-location = uri-reference> 
  <!-- Content: xs:schema --> 


The xsl:import-schema declaration identifies a namespace containing the names of the components to be imported (or indicates that components whose names are in no namespace are to be imported). The effect is that the names of top-level element and attribute declarations and type definitions from this namespace (or non-namespace) become available for use within XPath expressions in the stylesheet, and within other stylesheet constructs such as the type and as attributes of various XSLT elements.

The same schema components are available in all stylesheet modules; importing components in one stylesheet module makes them available throughout the stylesheet.

The namespace and schema-location elements are optional. The namespace attribute indicates that a schema for the given namespace is required by the stylesheet. This information may be enough on its own to enable an implementation to locate the required schema components. The namespace attribute may be omitted to indicate that a schema for names in no namespace is being imported. The zero-length string is not a valid namespace URI, and is therefore not a valid value for the namespace attribute.

The schema-location attribute is a URI Reference that describes where a schema document or other resource containing the required definitions may be found. It is likely that a schema-aware XSLT processor will be able to process a schema document found at this location.

The use of a namespace in an xsl:import-schema declaration does not by itself associate any namespace prefix with the namespace. If names from the namespace are used within the stylesheet module then a namespace declaration must be included in the stylesheet module, in the usual way.

You can also define an inline schema document using the xs:schema element as a child of xsl:import-schema. An inline schema document has the same status as an external schema document, in the sense that it acts as a hint for a source of schema components in the relevant namespace. To ensure that the inline schema document is always used, it is advisable to use a target namespace that is unique to this schema document.


The following example shows an inline schema document defined using the xs:schema subelement. This schema declares a simple type local:yes-no, which the stylesheet then uses in the declaration of a variable. The example assumes the namespace declaration xmlns:local="http://localhost/ns/yes-no".

  <xs:schema targetNamespace="http://localhost/ns/yes-no"> 
    <xs:simpleType name="local:yes-no"> 
      <xs:restriction base="xs:string"> 
        <xs:enumeration value="yes"/> 
        <xs:enumeration value="no"/> 
<xs:variable name="condition" select="'yes'" as="local:yes-no"/> 

Free Stylus Studio XML Training: