title: Remove duplicate elements and it's child nodes from input xml
body: <p>I have the payload in xml  format from which we have to remove the duplicate parent node and the corresponding child node in dataweave or xslt.</p>
  
  <pre><code>&lt;ns1:Hierarchy xmlns:ns1="http://www.example.org/Hierarchy" xmlns:ns2="http://www.example.org/HierarchyResult" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
     &lt;ns2:Parent&gt;19543007&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13277558&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13277558&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13599506&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13601740&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13277558&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13599506&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13735926&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13348972&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13601740&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13277558&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13599506&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;99000016191&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11465977&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
  &lt;/ns1:Hierarchy&gt;
  </code></pre>
  
  <p><strong>The desired output needs to be something like as below</strong></p>
  
  <pre><code> &lt;ns1:Hierarchy xmlns:ns1="http://www.example.org/Hierarchy" xmlns:ns2="http://www.example.org/HierarchyResult" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
     &lt;ns2:Parent&gt;19543007&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13277558&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13277558&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13599506&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;11465977&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;11580182&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13601740&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13709062&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13731947&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13735926&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14204010&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;14209921&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13601740&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13277558&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13599506&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13735926&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13348972&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
     &lt;ns2:Parent&gt;13601740&lt;/ns2:Parent&gt;
     &lt;ns2:Children&gt;
        &lt;ns2:Children&gt;13277558&lt;/ns2:Children&gt;
        &lt;ns2:Children&gt;13599506&lt;/ns2:Children&gt;
     &lt;/ns2:Children&gt;
  </code></pre>
  
  <p>Any help regarding this would be highly appreciated. I have tried various answers on dataweave and xslt but could filter out the duplicate items.</p>