Re: How To Include external XSL files into a master XSL file

Subject: Re: How To Include external XSL files into a master XSL file
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 16 Feb 2000 13:52:33 -0500
(I posted this answer to the original post of Jim's message to XML-Dev, and I think the answer would be of interest to others on this list so I am posting it again here)

At 00/02/16 12:25 -0600, Jim Garrett wrote:
What is the syntax to link multiple child style sheets into
a master style sheet ...

e.g.
header style sheet     header.xsl
footer style sheet      footer.xsl
data style sheet       data001.xsl
master style sheet.  master.xsl

this way i can always reference the master.xsl
style sheet from any/all   *.xml files
and then link in header.xsl (this one never changes)
then the appropriate data.xsl (this one changes)
then link the footer.xsl (this one never changes)

this way if I make any changes to the header
or the footer, they are edited in just one file
and reflected in all master.xsl files


<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org> <xsl:template match="/">

<!-- include the header.xsl file here -->
<!-- how to include syntax here -->

<!-- include the data.xsl file here -->
<!-- how to include syntax here -->

<!-- include the footer.xsl file here -->
<!-- how to include syntax here -->


</xsl:template> </xsl:stylesheet>

Your syntax above implies you want different snippets to be included in the root template, which can be done for the content of a single template, but I suspect you would rather want to include different sets of template rules into a single stylesheet.


If you must have a portion of a given template in an external file, you can use the XML external parsed general entities, but that syntactic scheme does not support reuse properly (though many coerce it to try). Personally, I don't put portions of templates in external files, rather, I use the <xsl:call-template> construct to accomplish what you are implying.

There are two semantic inclusion schemes at the top level of a stylesheet (children of the stylesheet container element): inclusion and importation.

You can use <xsl:include> to pull in top-level elements from another stylesheet and all such constructs are included as if they were edited in-situ (which sometimes can introduce problems accommodating template conflict resolution).

You can use <xsl:import> to pull in top-level elements from another stylesheet with the concept of "importance". This confers more importance on the importing stylesheet constructs than on the imported stylesheet constructs, without conflict. This is a powerful way to exploit an existing stylesheet with tweaks from an importing stylesheet.

also
what is the proper syntax in the included external xsl files

are they structured the same as the master.xsl file would
e.g.
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org>
<xsl:template match="/">

<!-- this is the header xsl file -->

</xsl:template>
</xsl:stylesheet>

Yes (with the caveat that again you appear to misconstrue the use of the declaration of the template for the root node) for included and imported stylesheets, but no for external parsed general entities (which are merely well-formed). Included and imported stylesheets are entire stylesheets in their own right.


If you are attending X-Tech in San Jose, I am teaching a two-day hands-on-with-exercises tutorial covering 100% of the constructs of XSLT. Please see http://www.gca.org/attend/2000_conferences/xtech_2000/default.htm for registration information. I am also teaching this material at other conferences (see our web site below for the conference course schedule) and companies in Europe, Japan and the U.S. are licensing our XSLT training materials for their own deliveries to their own customers.

I hope this helps.

.................. Ken


-- G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) Web site: XSL/XML/DSSSL/SGML services, training, libraries, products. Practical Transformation Using XSLT and XPath ISBN 1-894049-03-9 Next instructor-led training: 2000-02-27/28,2000-05-11/12,2000-05-15, - 2000-06-12,2000-06-13,2001-01-27


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread