Skip to main content

XSLT <xsl:import>

XSLT <xsl:import>

The <xsl:import> element is a top-level element that is used to import the contents of one style sheet into another.

note

An imported style sheet has lower precedence than the importing style sheet.

note

This element must appear as the first child node of <xsl:stylesheet> or <xsl:transform>.

Syntax

<xsl:import href="URI"/>

Attributes

AttributeValueRequired/OptionalDescription
hrefURIRequiredSpecifies the URI of the style sheet to import

Example

Suppose you have a style sheet called "bookstore_style.xsl":

bookstore_style.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<h2>The bookstore</h2>
<table border="1">
<tr bgcolor="#6565d5">
<th>Title</th>
<th>Author</th>
</tr>
<tr>
<td><xsl:value-of select="bookstore/book/title"/></td>
<td><xsl:value-of select="bookstore/book/author"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

And a second style sheet called "bookstore_import.xsl" imports "bookstore_style.xsl":

bookstore_import.xsl
<?xml version="1.0"  encoding="UTF-8"?>  
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="cdcatalog_ex3.xsl"/>

<xsl:template match="/">
<xsl:apply-imports/>
</xsl:template>

</xsl:stylesheet>