title: Limit XSLT apply-template to current node only?
body: <p>Is it possible to have xsl:apply-templates be limited to match the node only, without it trying to match nested elements?</p>
  
  <p>I understand I could use call-template.  Here are details on why I am trying to do this - </p>
  
  <p>I have a document composed of Section and Field elements.</p>
  
  <p>Section can contain nested Section elements or Field elements.  Field elements do not have nesting.</p>
  
  <p>As an example, for Field, a snippet of the template code is:</p>
  
  <pre><code>&lt;xsl:template match="Field" mode="Field"&gt;
  
      &lt;xsl:apply-templates select="." mode="FieldHeight" /&gt;
  
      .....
  
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="Field[LayoutTitlePosition = 'top']" mode="FieldHeight"&gt;
      &lt;xsl:attribute name="h" select="$glTopFieldHeight" /&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="Field[LayoutTitlePosition = ('left', 'right', 'none')]" mode="FieldHeight"&gt;
      &lt;xsl:attribute name="h" select="$glHorzFieldHeight" /&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>The same could be accomplished with xsl:choose / xsl:when statements, but I find the matching search parameters is nicer syntax and easier to maintain.  I'm able to maintain a common Field template and override specific parts based on the input.  Since Fields are not nested I don't need to be concerned about 'subFields' being matched.</p>
  
  <p>I want to do the same thing for Section headings, but the problem is if I apply a template to a Section, it will also potentially match nested sections.  This happens when I apply a template to a Section without a title that contains a subsection with a title - the subsection is getting matched twice.</p>
  
  <p><strong>EDIT</strong> Example of issue.</p>
  
  <p>I've attempted to create a minimal example to reproduce the issue.  The input document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Root&gt;
      &lt;Section&gt;
          &lt;!-- no title --&gt;
          &lt;Section&gt;
              &lt;Title&gt;Sub section title&lt;/Title&gt;
              &lt;Field&gt;
                  &lt;Type&gt;Text&lt;/Type&gt;
              &lt;/Field&gt;
          &lt;/Section&gt;
      &lt;/Section&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>The XSL transform document:</p>
  
  <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:output indent="yes" /&gt;
  
  &lt;xsl:template match="*" &gt;
      &lt;subform layout="tb"&gt;
          &lt;xsl:apply-templates select=".[name() = 'Section']" mode="Heading" /&gt;
          &lt;xsl:apply-templates select=".[name() = 'Field']" mode="Field" /&gt;
          &lt;xsl:apply-templates select="*[name() = ('Section', 'Field')]" /&gt;
      &lt;/subform&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="Section[Title]" mode="Heading"&gt;
      &lt;subform layout="tb"&gt;
          &lt;xsl:call-template name="drawHeading" /&gt;
      &lt;/subform&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="drawHeading"&gt;
      &lt;Heading&gt;&lt;xsl:value-of select="Title" /&gt;&lt;/Heading&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="Field" mode="Field"&gt;
      &lt;field name="{@Name}"&gt;
      &lt;/field&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>Output, from transforming the input document:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;subform layout="tb"&gt;
      &lt;subform layout="tb"&gt;
          &lt;subform layout="tb"&gt;
              &lt;Heading&gt;Sub section title&lt;/Heading&gt;
          &lt;/subform&gt;
          &lt;subform layout="tb"&gt;
              &lt;subform layout="tb"&gt;
                  &lt;Heading&gt;Sub section title&lt;/Heading&gt;
              &lt;/subform&gt;
              &lt;subform layout="tb"&gt;
                  &lt;field name=""/&gt;
              &lt;/subform&gt;
          &lt;/subform&gt;
      &lt;/subform&gt;
  &lt;/subform&gt;
  </code></pre>
  
  <p>It seemed the sub-section title is getting matched when the parent section without a title did not match.  </p>
  
  <p>The result I wanted to achieve is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;subform layout="tb"&gt;
      &lt;subform layout="tb"&gt;
  
          &lt;subform layout="tb"&gt;
              &lt;subform layout="tb"&gt;
                  &lt;Heading&gt;Sub section title&lt;/Heading&gt;
              &lt;/subform&gt;
              &lt;subform layout="tb"&gt;
                  &lt;field name=""/&gt;
              &lt;/subform&gt;
          &lt;/subform&gt;
      &lt;/subform&gt;
  &lt;/subform&gt;
  </code></pre>
  
  <p>If the Title is present in the source document, example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Root&gt;
      &lt;Section&gt;
          &lt;Title&gt;Section title&lt;/Title&gt;
          &lt;Section&gt;
              &lt;Title&gt;Sub section title&lt;/Title&gt;
              &lt;Field&gt;
                  &lt;Type&gt;Text&lt;/Type&gt;
              &lt;/Field&gt;
          &lt;/Section&gt;
      &lt;/Section&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>Then it should produce:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;subform layout="tb"&gt;
      &lt;subform layout="tb"&gt;
          &lt;subform layout="tb"&gt;
              &lt;Heading&gt;Section title&lt;/Heading&gt;
          &lt;/subform&gt;
          &lt;subform layout="tb"&gt;
              &lt;subform layout="tb"&gt;
                  &lt;Heading&gt;Sub section title&lt;/Heading&gt;
              &lt;/subform&gt;
              &lt;subform layout="tb"&gt;
                  &lt;field name=""/&gt;
              &lt;/subform&gt;
         &lt;/subform&gt;
     &lt;/subform&gt;
  &lt;/subform&gt;
  </code></pre>