title: Recursive deletion with apply template
body: <p>I'm trying to transform the following XML file, to remove each <code>&lt;AGGREGATION&gt;</code> node if followed by a <code>&lt;MULTIPLE&gt;</code> node.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;RECORD TEMPLATE="PRODUCTS" TRACK="1"&gt;
          &lt;FIELD NAME="PRODUCT" BASE="CT300" COUNT="2"&gt;
              &lt;AGGREGATION DOMAIN="4" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;TOKEN TEXT="CT300" BEGIN="11379" END="11384"/&gt;
              &lt;AGGREGATION DOMAIN="9" /&gt;
              &lt;AGGREGATION DOMAIN="4" /&gt;
              &lt;AGGREGATION DOMAIN="4" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;MULTIPLE TYPE="YES" /&gt;
              &lt;TOKEN TEXT="CT300" BEGIN="11379" END="11384"/&gt;
          &lt;/FIELD&gt;
      &lt;/RECORD&gt;
  </code></pre>
  
  <p>With the following xslt transformation, I was able to remove only the first occurrence of the <code>&lt;AGGREGATION&gt;</code> node:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;                        
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
    &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;   
  
  &lt;xsl:template match="//RECORD[@TEMPLATE='PRODUCTS']/FIELD[@NAME='PRODUCT']/AGGREGATION[following-sibling::*[1][self::MULTIPLE]]"&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="//RECORD[@TEMPLATE='PRODUCTS']/FIELD[@NAME='PRODUCT']/AGGREGATION[following-sibling::*[1][self::MULTIPLE]]"&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:copy&gt;
                  &lt;xsl:apply-templates select="@*|node()" /&gt;
              &lt;/xsl:copy&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;  
  &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>This is the output I receive:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;RECORD TEMPLATE="PRODUCTS" TRACK="1"&gt;
          &lt;FIELD BASE="CT300" COUNT="2" NAME="PRODUCT"&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;TOKEN BEGIN="11379" END="11384" TEXT="CT300"/&gt;
              &lt;AGGREGATION DOMAIN="9"/&gt;
              &lt;AGGREGATION DOMAIN="4"/&gt;
  
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;TOKEN BEGIN="11379" END="11384" TEXT="CT300"/&gt;
          &lt;/FIELD&gt;
     &lt;/RECORD&gt;
  </code></pre>
  
  <p>While the desired output is the following:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;RECORD TEMPLATE="PRODUCTS" TRACK="1"&gt;
          &lt;FIELD BASE="CT300" COUNT="2" NAME="PRODUCT"&gt;
  
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;TOKEN BEGIN="11379" END="11384" TEXT="CT300"/&gt;             
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;MULTIPLE TYPE="YES"/&gt;
              &lt;TOKEN BEGIN="11379" END="11384" TEXT="CT300"/&gt;
          &lt;/FIELD&gt;
   &lt;/RECORD&gt;
  </code></pre>
  
  <p>How can I implement a recursive deletion of the <code>&lt;AGGREGATION&gt;</code> node? </p>