<html>
<head>
<title>&lt;xsl:import&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:import&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
Allows you to import the templates found in another XSLT stylesheet. Unlike <span class="LITERAL">&lt;xsl:include&gt;</span>, all templates imported with <span class="LITERAL">&lt;xsl:import&gt;</span> have a lower priority than those in the including stylesheet. Another difference between <span class="LITERAL">&lt;xsl:include&gt;</span> and <span class="LITERAL">&lt;xsl:import&gt;</span> is that <span class="LITERAL">&lt;xsl:include&gt;</span> can appear anywhere in a stylesheet, while <span class="LITERAL">&lt;xsl:import&gt;</span> can appear only at the beginning.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Category</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Top-level element</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Required Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
href
</dt>
<dd>
Defines the URI of the imported stylesheet.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optional Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Content</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None. <span class="LITERAL">&lt;xsl:import&gt;</span> is an empty element.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Appears in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>
<span class="LITERAL">&lt;xsl:import&gt;</span> is a top-level element and can appear only as a child of <span class="LITERAL">&lt;xsl:stylesheet&gt;</span>. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT section 2.6.2, Stylesheet Import. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Here is a simple stylesheet that we'll import:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text"/&gt;

  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

<!--<?troff .Nd 10?>-->
  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:apply-templates select="list/title"/&gt;
    &lt;xsl:apply-templates select="list/listitem"/&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="title"&gt;
    &lt;xsl:value-of select="."/&gt;
    &lt;xsl:text&gt;: &lt;/xsl:text&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="listitem"&gt;
    &lt;xsl:text&gt;HERE IS LISTITEM NUMBER &lt;/xsl:text&gt;
    &lt;xsl:value-of select="position()"/&gt;
    &lt;xsl:text&gt;:  &lt;/xsl:text&gt;
    &lt;xsl:value-of select="."/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>We'll test both this stylesheet and the one that imports it with this XML document:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;list&gt;
  &lt;title&gt;A few of my favorite albums&lt;/title&gt;
  &lt;listitem&gt;A Love Supreme&lt;/listitem&gt;
  &lt;listitem&gt;Beat Crazy&lt;/listitem&gt;
  &lt;listitem&gt;Here Come the Warm Jets&lt;/listitem&gt;
  &lt;listitem&gt;Kind of Blue&lt;/listitem&gt;
  &lt;listitem&gt;London Calling&lt;/listitem&gt;
  &lt;listitem&gt;Remain in Light&lt;/listitem&gt;
  &lt;listitem&gt;The Joshua Tree&lt;/listitem&gt;
  &lt;listitem&gt;The Indestructible Beat of Soweto&lt;/listitem&gt;
&lt;/list&gt;</pre></span>
<p>When we process our XML source document with this stylesheet, here are the results:</p>
<span class="PROGRAMLISTING"><pre>
A few of my favorite albums:

HERE IS LISTITEM NUMBER 1:  A Love Supreme
HERE IS LISTITEM NUMBER 2:  Beat Crazy
HERE IS LISTITEM NUMBER 3:  Here Come the Warm Jets
HERE IS LISTITEM NUMBER 4:  Kind of Blue
HERE IS LISTITEM NUMBER 5:  London Calling
HERE IS LISTITEM NUMBER 6:  Remain in Light
HERE IS LISTITEM NUMBER 7:  The Joshua Tree
HERE IS LISTITEM NUMBER 8:  The Indestructible Beat of Soweto</pre></span>
<p>Now we'll use <span class="LITERAL">&lt;xsl:import&gt;</span> in another stylesheet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0"?&gt;
&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:import href="listitem.xsl"/&gt;

  &lt;xsl:output method="text"/&gt;

  &lt;xsl:variable name="newline"&gt;
&lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:variable&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:value-of select="$newline"/&gt;
    &lt;xsl:apply-templates select="list/title"/&gt;
    &lt;xsl:apply-templates select="list/listitem"/&gt;
  &lt;/xsl:template&gt;

  &lt;xsl:template match="listitem"&gt;
    &lt;xsl:value-of select="position()"/&gt;
    &lt;xsl:text&gt;.  &lt;/xsl:text&gt;
    &lt;xsl:value-of select="."/&gt;
    &lt;xsl:value-of select="$newline"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>Here are the results created by our second stylesheet:</p>
<span class="PROGRAMLISTING"><pre>
A few of my favorite albums:

1.  A Love Supreme
2.  Beat Crazy
3.  Here Come the Warm Jets
4.  Kind of Blue
5.  London Calling
6.  Remain in Light
7.  The Joshua Tree
8.  The Indestructible Beat of Soweto</pre></span>
<p>Notice that both stylesheets had a template with <span class="LITERAL">match="listitem"</span>. The template in the imported stylesheet has a lower priority, so it is not used. Only the imported stylesheet has a template with <span class="LITERAL">match="title"</span>, so the imported template is used for the <span class="LITERAL">&lt;title&gt;</span> element. </p>
</td>
</tr>
</table>
</div>
</body>
</html>