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, while <xsl:import>
can appear only at the beginning.
Category
Top-level element
Required Attributes
- 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
XSLT section 2.6.2, Stylesheet Import.
Example
Here is a simple stylesheet that we’ll import:
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="newline"> <xsl:text> </xsl:text> </xsl:variable> <xsl:template match="/"> <xsl:value-of select="$newline"/> <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:value-of select="$newline"/> <xsl:value-of select="$newline"/> </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:value-of select="$newline"/> </xsl:template> </xsl:stylesheet> ...
Get XSLT 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.