Name
<xsl:include>
Allows you to include another XSLT stylesheet. This
element allows you to put common transformations in a separate
stylesheet, then include the templates from that stylesheet at any
time. Unlike <xsl:import>,
all templates included with <xsl:include> have the same priority
as those in the including stylesheet. Another difference is that
<xsl:include> can appear
anywhere in a stylesheet, whereas <xsl:import> must appear at the
beginning.
Category
Top-level element.
Required Attribute
hrefThe URI of the included stylesheet.
Optional Attributes
None.
Content
None. <xsl:include> is
an empty element.
Appears in
<xsl:include> is a
top-level element and can appear only as a child of <xsl:stylesheet>.
Defined in
[1.0] XSLT section 2.6.1, “Stylesheet Inclusion.”
[2.0] XSLT section 3.10.2, “Stylesheet Inclusion.”
Example
The <xsl:include>
element is a good way to break your stylesheets into smaller pieces;
those smaller pieces are often easier to reuse. Here’s a short
stylesheet that includes another:
<?xml version="1.0"?> <!-- include.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="include-stylesheet.xsl"/> <xsl:output method="text"/> <xsl:template match="/"> <xsl:value-of select="/report/title"/> <xsl:text>

</xsl:text> <xsl:for-each select="report/brand"> <xsl:text> </xsl:text> <xsl:value-of select="name"/> <xsl:text>: </xsl:text> <xsl:value-of select="format-number(units, '##,###')"/> <xsl:text> bars sold. </xsl:text> ...
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