Freigeben über


<xsl:import> Element 

Imports another XSLT file.

<xsl:import
  href = "uri-reference" />

Attributes

  • href
    Required. A Uniform Resource Identifier (URI) reference that identifies the XSLT file to be imported.

Element Information

Number of occurrences

Unlimited

Parent elements

xsl:stylesheet, xsl:transform

Child elements

(No child elements)

Remarks

An XSLT file can import another XSLT file using an <xsl:import> element. Importing an XSLT file is the same as including it except that definitions and template rules in the importing file take precedence over those in the imported XSLT file. The <xsl:import> element has an href attribute whose value is a URI reference identifying the style sheet to be imported. A relative URI is resolved relative to the base URI of the <xsl:import> element.

The <xsl:import> element is allowed only as a top-level element. The <xsl:import> element children must precede all other element children of an <xsl:stylesheet> element, including any <xsl:include> element children. When <xsl:include> is used to include a style sheet, any <xsl:import> elements in the included document are moved up in the included document to follow any existing <xsl:import> elements in the included document.

The <xsl:stylesheet> elements encountered during processing of a style sheet that contains <xsl:import> elements are treated as forming an import tree. In the import tree, each <xsl:stylesheet> element has one import child for each <xsl:import> element that it contains. Any <xsl:include> elements are resolved before constructing the import tree. An <xsl:stylesheet> element in the import tree is defined to have lower import precedence than another <xsl:stylesheet> element in the import tree if it would be visited before that <xsl:stylesheet> element in a post-order traversal of the import tree (that is, a traversal of the import tree in which an <xsl:stylesheet> element is visited after its import children). Each definition and template rule has import precedence determined by the <xsl:stylesheet> element that contains it.

For example, assume the following conditions are true.

  • XSLT file A imports XSLT files B and C, in that order.

  • XSLT file B imports XSLT file D.

  • XSLT file C imports XSLT file E.

The order of import precedence (lowest first) is D, B, E, C, A.

Note

Because <xsl:import> elements are required to occur before any definitions or template rules, an implementation that processes imported XSLT files at the point at which it encounters the <xsl:import> element will encounter definitions and template rules in increasing order of import precedence.

In general, a definition or template rule with higher import precedence takes precedence over a definition or template rule with lower import precedence. This is defined in detail for each kind of definition and for template rules.

It is an error if an XSLT file directly or indirectly imports itself. Apart from this, the case where an XSLT file with a particular URI is imported in multiple places is not treated specially. The import tree will have a separate <xsl:stylesheet> element for each place that it is imported.

Note

If <xsl:apply-imports> is used, the behavior may be different from the behavior if the XSLT file had been imported only at the place with the highest import precedence.

XSLT File (importer.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:import href="article.xsl"/>
<xsl:import href="bigfont.xsl"/>

<xsl:attribute-set name="note-style">
   <xsl:attribute name="font-style">italic</xsl:attribute>
</xsl:attribute-set>

</xsl:stylesheet>

Also see the following topic:

See Also

Reference

<xsl:include> Element
<xsl:apply-imports> Element