Importing XSLTs

Welcome to our free XSLT 1.0 and XPath 1.0 tutorial. This tutorial is based on Webucator's XSLT 1.0 and XPath 1.0 Training course.

Contact Us or call 1-877-932-8228
Importing XSLTs

Importing XSLTs

Importing one XSLT into another is very similar to including it. The only difference is that, when importing, templates defined in the importing XSLT take precedence over templates in the imported XSLT. In other words, if there are conflicting templates, the template in the imported XSLT is ignored.

The xsl:import element must be the first element after the open xsl:stylesheet tag. Here is an example of a document that imports HTML.xsl.

Code Sample:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	<xsl:import href="HTML.xsl"/>
	<xsl:output method="xml" indent="yes"/>
	<xsl:template match="/">
		<xsl:call-template name="StartHTML">
			<xsl:with-param name="Title" select="'Beatles'"/>
	<xsl:template match="beatle[not(@real='no')]">
		<li style="color:blue;"><xsl:apply-templates/></li>
	<xsl:template match="beatle">
		<li style="color:red; text-decoration:line-through">
	<xsl:template match="name">
		<xsl:value-of select="lastname"/>,
		<xsl:value-of select="firstname"/>

In these examples there is no difference between including and importing HTML.xsl. The difference only comes into play when the including/importing XSLT has conflicting templates with the included/imported XSLT. To see how it works, transform MultipleDocs/Demos/BeatlesImport.xml against MultipleDocs/Demos/BeatlesImport.xsl.


This tutorial is based on Webucator's XSLT 1.0 and XPath 1.0 Training Course. We also offer many other XML Training courses. Sign up today to get help from a live instructor.