<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, while <xsl:import> must appear at the beginning.
Category
Top-level element
Required Attributes
href Defines the 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
XSLT section 2.6.1, 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.) In our case study (see Chapter 9), we had a number of different stylesheets, each of which contained templates for a particular purpose. Here's how our <xsl:include> elements look:
    <xsl:include href="toot-o-matic-variables.xsl"/>

    <xsl:include href="xslt-utilities.xsl"/>
    <xsl:include href="dw-style.xsl"/>

    <xsl:include href="build-main-index.xsl"/>
    <xsl:include href="build-section-indexes.xsl"/>
    <xsl:include href="build-individual-panels.xsl"/>
    <xsl:include href="build-graphics.xsl"/>
    <xsl:include href="build-pdf-file.xsl"/>
    <xsl:include href="build-zip-file.xsl"/>
Segmenting your stylesheets this way can make debugging simpler, as well. In our example here, all the rules for creating a PDF file are in the stylesheet build-pdf-file.xsl. If the PDF files are not built correctly, build-pdf-file.xsl is most likely the source of the problem. All visual elements of our generated HTML pages are created in the stylesheet dw-style.xsl. If we need to change the look of all the HTML pages, changing the templates in dw-style.xsl will do the trick.