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
hrefDefines 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> ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access