xsl:include Element (Windows CE 5.0)
Specifies an XSL Transformation (XSLT) style sheet to include.
<xsl:includehref ="URI-reference" />
Attributes
- href
[required] A Uniform Resource Identifier (URI) reference identifying the style sheet to be included.
Element Information
Number of occurrences | Unlimited |
Parent elements | xsl:stylesheet, xsl:transform |
Child elements | (No child elements) |
Remarks
An XSLT style sheet can include another XSLT style sheet using the <xsl:include> element. The href attribute value is a URI reference identifying the style sheet to be included. The relative URI is resolved with relation to the base URI of the <xsl:include> element.
The <xsl:include> element is only allowed as the child of the <xsl:stylesheet> element.
Inclusions are processed in the Microsoft® XML Parser (MSXML) as if they occurred at the tree level. Note that this is not the same as the Document Object Model (DOM) view of the XML tree. The resource located by the href attribute value is parsed as an XML document, and the children of the <xsl:stylesheet> element in this document replace the <xsl:include> element in the including document. The fact that template rules or definitions are included does not affect the way they are processed.
An error occurs if a style sheet directly or indirectly includes itself.
Including a style sheet multiple times can cause errors because of duplicate definitions. Such multiple inclusions are less obvious when they are indirect. For example, if style sheet B includes style sheet A, style sheet C includes style sheet A, and style sheet D includes both style sheet B and style sheet C, then A will be included indirectly by D twice. If all of B, C, and D is used as independent style sheets, the error can be avoided by separating everything in B other than the inclusion of A into a separate style sheet B1 and changing B to contain just inclusions of B1 and A, doing the same for C, and then changing D to include A, B1, C1.
Example
The following sample demonstrates the use of the <xsl:include> element.
The XML file
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xslinclude.xsl"?>
<COLLECTION>
<BOOK>
<TITLE>Developing XML Solutions</TITLE>
<AUTHOR>Jake Sturm</AUTHOR>
<PUBLISHER>Microsoft Programming Series</PUBLISHER>
</BOOK>
<BOOK>
<TITLE>HTML and XML for beginners</TITLE>
<AUTHOR>Michael Morrison</AUTHOR>
<PUBLISHER>Microsoft Press</PUBLISHER>
</BOOK>
<BOOK>
<TITLE>XML Step by Step</TITLE>
<AUTHOR>Michael Young</AUTHOR>
<PUBLISHER>Microsoft Press</PUBLISHER>
</BOOK>
</COLLECTION>
xslinclude.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:space="preserve">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:for-each select="COLLECTION/BOOK">
<xsl:apply-templates select="TITLE"/>
<xsl:apply-templates select="AUTHOR"/>
<xsl:apply-templates select="PUBLISHER"/>
<BR/> <!-- add this -->
</xsl:for-each>
</xsl:template>
<xsl:include href="xslincludefile.xsl" />
</xsl:stylesheet>
xslincludefile.xsl
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:space="preserve">
<xsl:template match="TITLE">
Title - <xsl:value-of select="."/><BR/>
</xsl:template>
<xsl:template match="AUTHOR">
Author - <xsl:value-of select="."/><BR/>
</xsl:template>
<xsl:template match="PUBLISHER">
Publisher - <xsl:value-of select="."/><BR/><!-- removed second <BR/> -->
</xsl:template>
</xsl:stylesheet>
Output
Title - Developing XML Solutions
Author - Jake Sturm
Publisher - Microsoft Programming Series
Title - HTML and XML for beginners
Author - Michael Morrison
Publisher - Microsoft Press
Title - XML Step by Step
Author - Michael Young
Publisher - Microsoft Press
See Also
XSLT Elements | xsl:import Element
Send Feedback on this topic to the authors