<html>
<head>
<title>&lt;xsl:apply-templates&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:apply-templates&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">
Instructs the XSLT processor to apply the appropriate templates to a node-set.  </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>Instruction</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">
<p>None.</p>
</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">
<dl>
<dt>
select
</dt>
<dd>
Contains an XPath expression that selects the nodes to which templates should be applied. Valid values include
<span class="LITERAL">
*
</span>
to select the entire node-set. Without this attribute, all element children of the current node are selected.
<P></p>
<dt>
mode
</dt>
<dd>
Defines a processing mode, a convenient syntax that lets you write specific templates for specific purposes. For example, I could write an
<span class="LITERAL">
&lt;
xsl:template
&gt;
</span>
with
<span class="LITERAL">
mode=
"
toc
"
</span>
to process a node for the table of contents of a document, and other
<span class="LITERAL">
&lt;
xsl:template
&gt;
</span>
s with
<span class="LITERAL">
mode=
"
print
"
</span>
,
<span class="LITERAL">
mode=
"
online
"
</span>
,
<span class="LITERAL">
mode=
"
index
"
</span>
, etc. to process the same information for different purposes.
<P></p>
</dl>
</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>The <span class="LITERAL">&lt;xsl:apply-templates&gt;</span> element can contain any number of <span class="LITERAL">&lt;xsl:sort&gt;</span> and <span class="LITERAL">&lt;xsl:with-param&gt;</span> elements.  In most cases, <span class="LITERAL">&lt;xsl:apply-templates&gt;</span> is empty. </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:apply-templates&gt;</span> appears inside a template.</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 5.4, Applying Template Rules. </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>In our case study (see <link linkend="xslt-CHP-9">Chapter 9</link>), we needed to create several different outputs from the same data.  We addressed this need with the <span class="LITERAL">mode</span> attribute of the <span class="LITERAL">&lt;xsl:apply-templates&gt;</span> element.  Here's the main template (<span class="LITERAL">match="/"</span>):</p>
<span class="PROGRAMLISTING"><pre>
&lt;xsl:template match="/"&gt;
  &lt;xsl:apply-templates select="tutorial" mode="build-main-index"/&gt;
  &lt;redirect:write select="concat($curDir, $fileSep, 'index.html')"&gt; 
    &lt;xsl:apply-templates select="tutorial" mode="build-main-index"/&gt;
  &lt;/redirect:write&gt;
  &lt;xsl:apply-templates select="tutorial" mode="build-section-indexes"/&gt;
  &lt;xsl:apply-templates select="tutorial" mode="build-individual-panels"/&gt;
  &lt;xsl:apply-templates select="tutorial" mode="generate-graphics"/&gt;
  &lt;xsl:apply-templates select="tutorial" mode="generate-pdf-file"&gt;
    &lt;xsl:with-param name="page-size" select="'ltr'"/&gt;
  &lt;/xsl:apply-templates&gt;
<!--<?troff .Nd 10?>-->
  &lt;xsl:apply-templates select="tutorial" mode="generate-pdf-file"&gt;
    &lt;xsl:with-param name="page-size" select="'a4'"/&gt;
  &lt;/xsl:apply-templates&gt;
  &lt;xsl:apply-templates select="tutorial" mode="generate-zip-file"/&gt;
&lt;/xsl:template&gt;</pre></span>
<p>Notice that this example selects the <span class="LITERAL">&lt;tutorial&gt;</span> element eight times, but applies templates with a different mode (or different parameters for the same mode) each time. </p>
</td>
</tr>
</table>
</div>
</body>
</html>