xsl:import Element (Compact 2013)
3/26/2014
Imports another XSL Transformations (XSLT) style sheet.
Syntax
<xsl:import
href = "URI-reference" />
Attributes
- href
[required] This is a Uniform Resource Identifier (URI) reference identifying the style sheet to be imported.
Element Information
Number of occurrences |
Unlimited |
Parent elements |
|
Child elements |
None |
Remarks
An XSLT style sheet can import another XSLT style sheet using an <xsl:import> element. Importing a style sheet is the same as including it except that definitions and template rules in the importing style sheet take precedence over those in the imported style sheet. 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.
- Style sheet A imports style sheets B and C, in that order.
- Style sheet B imports style sheet D.
- Style sheet C imports style sheet 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 style sheets 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 a style sheet directly or indirectly imports itself. Apart from this, the case where a style sheet 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 style sheet had been imported only at the place with the highest import precedence.
Example
<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>