xsl:import
xsl:apply-imports
xsl:stylesheet
xsl:template
ELEMENT: xsl:include
<xsl:include
href="uri"
/>
The
xsl:include
element is used to add (include) a stylesheet to another. You can repeat this element in order to include more than one stylesheet.
The definitions and template rules of the included stylesheet are treated equal to the definitions and template rules of the including stylesheet. The effect is the same as if the included stylesheet was actually part of the stylesheet with which it is being included.
An analogy can be made about this element with regard to the #include used in the C computer language.
The similar
xsl:import
element is also used to add (import) a stylesheet to another, but the definitions and template rules of the importing stylesheet are treated as having greater importance than the definitions and template rules of the imported stylesheet.
The
xsl:include
element can only occur as a child of the
xsl:stylesheet
element. All
xsl:include
elements must occur after all
xsl:import
elements.
A stylesheet cannot include itself, either directly or indirectly. Nor should a stylesheet be included more than once, either directly or indirectly. Both situations may cause errors due to duplication.
This is a self-closing element and it cannot contain any child elements or any content.
href="uri"
The mandatory
href
attribute is either a relative or absolute URI (Uniform Resource Identifier) address of a valid stylesheet to be included. A relative URI is resolved against the base URI of the XML source document.
We use the
DevGuru Staff List XML file
for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_include.xsl"?>
and we name it: xslt_example_include.xml
We include:
xslt_example_template.xsl
(will appear in separate window - use "view source" to see code)
Code for xslt_example_include.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<
xsl:include href="xslt_example_template.xsl" /
>
<xsl:template match="devguru_staff/programmer">
<html>
<body>
<xsl:apply-templates select="name" />
<xsl:apply-templates select="dob" />
<xsl:apply-templates select="age" />
<br />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:
Click to view output in separate window
- requires Internet Explorer
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information