title: XSLT 'apply-templates' and 'apply-templates with mode' in a single go
body: <p>I am trying to use apply-templates and apply-templates with mode like explained in the below example:</p>
  
  <p>My input xml looks like:</p>
  
  <pre><code>&lt;catalog&gt;
  &lt;product dept="aaa"&gt;
      &lt;number&gt;111&lt;/number&gt;
      &lt;name&gt;cap&lt;/name&gt;
      &lt;color&gt;blue&lt;/color&gt;
  &lt;/product&gt;
  &lt;product dept="bbb"&gt;
      &lt;number&gt;222&lt;/number&gt;
      &lt;name&gt;bat&lt;/name&gt;
      &lt;color&gt;white&lt;/color&gt;
  &lt;/product&gt;
  &lt;product dept="ccc"&gt;
      &lt;number&gt;333&lt;/number&gt;
      &lt;name&gt;bag&lt;/name&gt;
      &lt;color&gt;red&lt;/color&gt;
  &lt;/product&gt;
  </code></pre>
  
  <p></p>
  
  <p>Now I am trying with the below shown xslt to remove the product element with dept=bbb but it doesn't work. The same input xml appears in the output. I know I can achieve my desired result by removing the mode attribute on the last template but I am trying to understand why it doesn't work in the way I'm trying here.</p>
  
  <pre><code>    &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" version="1.0" exclude-result-prefixes="exsl"&gt;
    &lt;xsl:template match="/"&gt;
      &lt;xsl:variable name="modXml"&gt;
        &lt;xsl:apply-templates /&gt;
        &lt;xsl:apply-templates mode="remove" /&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:copy-of select="exsl:node-set($modXml)/*" /&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="node( ) | @*"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="@*" /&gt;
        &lt;xsl:apply-templates /&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="/catalog/product[@dept='bbb']" mode="remove" /&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Can someone please explain how the XSLT processor is running the transformation here..?</p>
  
  <p>Thanks a lot..!</p>