12.9 Modes and Priorities

<?xml version="1.0" encoding="utf-8" ?>  
<xsl:stylesheet version="1.0"  
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
>  
  <xsl:template match="article">  
     <xsl:copy>  
       <toc>  
         <xsl:apply-templates mode="toc" />  
       </toc>  
       <xsl:apply-templates/>  
     </xsl:copy>  
  </xsl:template>  
 
  <xsl:template match="*">  
     <xsl:copy>  
       <xsl:apply-templates/>  
     </xsl:copy>  
  </xsl:template>  
 
  <xsl:template match="title" mode="toc" >  
    <xsl:text>&#x000A;</xsl:text>  
    <entry>  
      <xsl:apply-templates/>  
    </entry>  
  </xsl:template>  
 
  <xsl:template match="*" mode="toc" >  
     <xsl:apply-templates mode="toc" />  
  </xsl:template>  
 
  <xsl:template match="text()" mode="toc" />  
 
</xsl:stylesheet>  
<?xml version="1.0"  
      encoding="utf-8" ?>  
<article>  
  <section>  
    <title>Section 1</title>  
    Body 1.  
  <section>  
  </section>  
    <title>Section 2</title>  
    Body 2.  
  </section>  
</article>  
<?xml version="1.0" encoding="UTF-8"?>  
<article><toc>  
<entry>Section 1</entry>  
<entry>Section 2</entry></toc>  
  <section>  
    <title>Section 1</title>  
    Body 1.  
  <section>  
  </section>  
    <title>Section 2</title>  
    Body 2.  
  </section>  
</article>