Name
<xsl:import>
Allows you to import the templates found in another XSLT
stylesheet. Unlike <xsl:include>
, all templates imported
with <xsl:import>
have a
lower priority than those in the including stylesheet. Another
difference between <xsl:include>
and <xsl:import>
is that <xsl:include>
can appear anywhere in a
stylesheet, whereas <xsl:import>
can appear only at the
beginning.
Category
Top-level element.
Required Attribute
href
Defines the URI of the imported stylesheet.
Optional Attributes
None.
Content
None. <xsl:import>
is
an empty element.
Appears in
<xsl:import>
is a
top-level element and can appear only as a child of <xsl:stylesheet>
.
Defined in
[1.0] XSLT section 2.6.2, “Stylesheet Import.”
[2.0] XSLT section 3.10.3, “Stylesheet Import.”
Example
Here is a simple stylesheet that we’ll import:
<?xml version="1.0"?>
<!-- listitem.xsl -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:text>
</xsl:text>
<xsl:apply-templates select="list/title"/>
<xsl:apply-templates select="list/listitem"/>
</xsl:template>
<xsl:template match="title">
<xsl:value-of select="."/>
<xsl:text>: </xsl:text>
<xsl:text>
</xsl:text>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="listitem">
<xsl:text>HERE IS LISTITEM NUMBER </xsl:text>
<xsl:value-of select="position()"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
To illustrate how <xsl:import> ...
Get XSLT, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.