title: XSLT Exclude Specific Tags
body: <p>I have a problem i am trying to resolve in an XSLT but i an unable to find a solution. The example below is related to a payment system it is adding items to a basket then removing them. The out XML provides a audit trail of actions conducted on a basket.</p>
  <h3>Senario:</h3>
  <p>Add Item (Id 1)</p>
  <p>Add Item (Id 1) With a price change</p>
  <p>Void Item (Id 1)</p>
  <p>Void Item (Id 1) With a price change</p>
  <p>Add Item (Id 1)</p>
  <p>Add Item (Id 1)</p>
  <h3>Expected Outcome</h3>
  <p>Remove:</p>
  <p>Add Item (Id 1)</p>
  <p>Add Item (Id 1) With a price change</p>
  <h3>Output XML Contains</h3>
  <p>Void Item (Id 1)</p>
  <p>Void Item (Id 1) With a price change</p>
  <p>Add Item (Id 1)</p>
  <p>Add Item (Id 1)</p>
  <p>Input XML:</p>
  <pre><code>&lt;xml&gt;
      &lt;product void=&quot;false&quot;&gt;
          &lt;sequence_number&gt;1&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
      &lt;/product&gt;
      &lt;product void=&quot;false&quot;&gt;
          &lt;sequence_number&gt;2&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
          &lt;price_change&gt;
              &lt;price&gt;10&lt;/price&gt;
          &lt;/price_change&gt;
      &lt;/product&gt;
      &lt;product void=&quot;true&quot;&gt;
          &lt;sequence_number&gt;3&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
          &lt;price_change&gt;
              &lt;price&gt;10&lt;/price&gt;
          &lt;/price_change&gt;
      &lt;/product&gt;
      &lt;product void=&quot;true&quot;&gt;
          &lt;sequence_number&gt;4&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
      &lt;/product&gt;
      &lt;product void=&quot;false&quot;&gt;
          &lt;sequence_number&gt;5&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
      &lt;/product&gt;
      &lt;product void=&quot;false&quot;&gt;
          &lt;sequence_number&gt;6&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
      &lt;/product&gt;
  &lt;/xml&gt;
  </code></pre>
  <p>Expected outcome:</p>
  <pre><code>&lt;xml&gt;
      &lt;product void=&quot;true&quot;&gt;
          &lt;sequence_number&gt;3&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
          &lt;price_change&gt;
              &lt;price&gt;10&lt;/price&gt;
          &lt;/price_change&gt;
      &lt;/product&gt;
      &lt;product void=&quot;true&quot;&gt;
          &lt;sequence_number&gt;4&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
      &lt;/product&gt;
      &lt;product void=&quot;false&quot;&gt;
          &lt;sequence_number&gt;5&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
      &lt;/product&gt;
      &lt;product void=&quot;false&quot;&gt;
          &lt;sequence_number&gt;6&lt;/sequence_number&gt;
          &lt;item_id&gt;11111111&lt;/item_id&gt;
          &lt;price&gt;12&lt;/price&gt;
      &lt;/product&gt;
  &lt;/xml&gt;
  </code></pre>
  <p>XSLT</p>
  <pre><code>&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
      
      &lt;xsl:template match=&quot;@*|node()&quot;&gt;
          &lt;xsl:copy&gt;
              &lt;xsl:apply-templates select=&quot;@*|node()&quot;/&gt;
          &lt;/xsl:copy&gt;
      &lt;/xsl:template&gt;
      
      
      &lt;xsl:template match=&quot;//product[@void='false']&quot;&gt;
          
          &lt;xsl:if test=&quot;item_id != //product[@void='true']/item_id&quot;&gt;
              &lt;xsl:copy&gt;
                  &lt;xsl:apply-templates select=&quot;@*|node()&quot;/&gt;
              &lt;/xsl:copy&gt;
          &lt;/xsl:if&gt;
          
      &lt;/xsl:template&gt;
      
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>The problem with this is that it is deleting all products that are not voided and have the same id and not taking into account the number of void items vs the number of none void items.</p>
  <p>If you have 1 void item it should only delete one product that is not voided but has exactly the same tags as itself</p>