The <xsl:include> Element

Another way to insert stylesheets inside other documents is to use the <xsl:include> element. This element enables you to include the contents of a file at a particular place in a stylesheet. This element has only one attribute:

  • href (mandatory). The URI of the stylesheet you want to include.

This element is empty and has no content.

Here’s an example. In this case, I’ll put part of the stylesheet in planets.xsl into a new document, rules.xml. Then I can include rules.xml in planets.xsl:

Listing 2.9. Including a Stylesheet
 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:include href="rules.xsl"/> <xsl:template match="/PLANETS"> <HTML> <HEAD> <TITLE> The Planets ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.