title: How to match nodes in xslt only once and filter them out
body: <p>I have a file with two types of &quot;journal source&quot;. Below is a small sample file</p>
  <pre><code>&lt;File&gt;   
     &lt;Record&gt;
          &lt;employee&gt;935388&lt;/employee&gt;
          &lt;journal_source&gt;Procurement_Card_Transaction_Verification&lt;/journal_source&gt;
          &lt;amount&gt;26.31&lt;/amount&gt;
          &lt;wid&gt;123&lt;/wid&gt;
          &lt;concat_values&gt;935388|Procurement_Card_Transaction_Verification|26.31&lt;/concat_values&gt;
          &lt;Created_Moment&gt;2020-12-31T20:45:45.415-08:00&lt;/Created_Moment&gt;
          &lt;Accounting_Date&gt;2020-12-31-08:00&lt;/Accounting_Date&gt;
     &lt;/Record&gt;   
     &lt;Record&gt;
        &lt;employee&gt;935388&lt;/employee&gt;
        &lt;journal_source&gt;Credit_Card_Transaction_Load&lt;/journal_source&gt;
        &lt;amount&gt;-26.31&lt;/amount&gt;
        &lt;wid&gt;abc&lt;/wid&gt;
        &lt;concat_values&gt;935388|Credit_Card_Transaction_Load|26.31&lt;/concat_values&gt;
        &lt;Created_Moment&gt;2020-12-20T20:45:45.415-08:00&lt;/Created_Moment&gt;
        &lt;Accounting_Date&gt;2020-12-31-08:00&lt;/Accounting_Date&gt;
     &lt;/Record&gt;
     &lt;Record&gt;
        &lt;employee&gt;935388&lt;/employee&gt;
        &lt;journal_source&gt;Credit_Card_Transaction_Load&lt;/journal_source&gt;
        &lt;amount&gt;-26.31&lt;/amount&gt;
        &lt;wid&gt;def&lt;/wid&gt;
        &lt;concat_values&gt;935388|Credit_Card_Transaction_Load|26.31&lt;/concat_values&gt;
        &lt;Created_Moment&gt;2020-12-20T20:45:45.415-08:00&lt;/Created_Moment&gt;
        &lt;Accounting_Date&gt;2020-12-31-08:00&lt;/Accounting_Date&gt;
     &lt;/Record&gt;   
  &lt;/File&gt;
  </code></pre>
  <p>The goal is to only output nodes with a journal_source type of &quot;Credit_Card_Transaction_Load&quot; that do not have a matching &quot;Procurement_Card_Transaction_Verification&quot; that also has a &quot;Created_Moment&quot; that is greater than that of the credit card transaction. By matching, I mean they have the same value for &quot;concat_values&quot; field except one is Credit and the other Procurement.</p>
  <p>The tricky part here is that I can only match a procurement transaction once. After it has been used, I can't take it into account for other credit card transactions even if they also match. Below is an example of what the output would need to be for the sample provided previously (only interested in getting the &quot;wid&quot; field in the output):</p>
  <pre><code>&lt;File&gt;   
      
          &lt;wid&gt;def&lt;/wid&gt;
  
  &lt;/File&gt;
  </code></pre>
  <p>I first thought of keeping track of the used procurement transactions by updating a map or a variable in a foreach loop. I would then make sure to check if that transaction had already been used to match another credit card transaction previously. However, this doesn't work because variables are immutable.</p>
  <p>I also thought about exploring XSLT 3 features and tried to look at accumulators but I didn't get very far.</p>
  <p>Any help would be appreciated!</p>