<s1 title="XSL Modes">

<p>XSL modes are an advanced XSL feature.  Some pages need to evaluate
the same XML twice.  For example, a table of contents needs to create
lists of the section titles, but the "normal" printing needs to output
the section contents.

<p>XSL adds <var/modes/> to process XML elements in different ways.
If the stylesheet specifies the mode attribute in xsl:apply-templates,
the XSL engine will only match templates with the matching mode.

<p>The following example has two modes: the default mode and a
"summary" mode.  The summary mode is used to generate a table of
contents.  The &lt;summary/> tag creates the table of contents.  It
calls xsl:apply-templates with the summary mode.  The only template in
summary mode is a section template.  It will add items to the table
of contents.</p>

<example title='default.xsl'>
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

&lt;xsl:template match="section" mode="summary">
  &lt;li>&lt;xsl:value-of select="@title"/>
  &lt;xsl:if test="section">
    &lt;ol>&lt;xsl:apply-templates mode="summary"/>&lt;/ol>
  &lt;/xsl:if>
&lt;/li>
&lt;/xsl:template>

&lt;xsl:template match="summary">
&lt;ol>
  &lt;xsl:apply-templates select="../section" mode="summary"/>
&lt;/ol>
&lt;/xsl:template>

&lt;template match="section">
&lt;/template>

&lt;/xsl:stylesheet>
</example>

<p>To simplify the example, the template for &lt;section> does
nothing.  So only the summary will be generated from the XTP file.</p>

<example title='hello.xtp'>
&lt;summary/>

&lt;section title="First Section">
Some text

&lt;section title="Subsection A">
Subtext
&lt;/section>

&lt;section title="Subsection B">
Subtext
&lt;/section>
&lt;/section>

&lt;section title="Second Section">
Draft text
&lt;/section>
</example>
<results>
&lt;ol>
  &lt;li>First Section
  &lt;ol>
    &lt;li>Subsection A&lt;/li>
    &lt;li>Subsection B&lt;/li>
  &lt;/ol>
  &lt;/li>
  &lt;li>Second Section&lt;/li>
&lt;/ol>
</results>

<s2 title="Strict XSL">

<p>The StyleScript equivalent shows how to add arbitrary attributes
in a StyleScript function. <var/foo/>=><var/bar/> will set the value
<var/bar/> to the attribute <var/foo/>.</p>

<example title='default.xsl'>
$template(section, mode=>summary) &lt;&lt;
&lt;li>$(@title)
  $if (section) <<
    &lt;ol>$apply-templates(mode=>summary);&lt;/ol>
  >>
&lt;/li>
>>

$template(summary) &lt;&lt;
&lt;ol>
  $apply-templates(../section, mode=>summary);
&lt;/ol>
>>

$template(section) &lt;&lt;
>>
</example>

</s2>

<s2 title="Summary">

<ul>
<li><var/modes/> let stylesheets extract new formats from the same XML.
<li><var/name=>value/> specifies named attributes in XTP.
<li><var/$if/> conditionally evaluates part of a stylesheet.
<li>The XPath pattern <var/../a/> selects all the siblings of a.
</ul>

</s2>
</s1>
