title: Separate duplicates from unique
body: <p>I tried with many XSLT methods like Key, for-each-group and match method options, but it is not working for me.</p>
  <p>Input XML:</p>
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;CustomerRecord&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;ABC&lt;/chargeto&gt;
          &lt;chargename&gt;GARY&lt;/chargename&gt;
      &lt;/Customer&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;XYZ&lt;/chargeto&gt;
          &lt;chargename&gt;DAVIS&lt;/chargename&gt;
      &lt;/Customer&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;CDE&lt;/chargeto&gt;
          &lt;chargename&gt;GARY DAVIS&lt;/chargename&gt;
      &lt;/Customer&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;ABC&lt;/chargeto&gt;
          &lt;chargename&gt;DAV&lt;/chargename&gt;
      &lt;/Customer&gt;
  &lt;/CustomerRecord&gt;
  </code></pre>
  <p>Expected output XML:</p>
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;Root&gt;
  &lt;Customer_PO&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;ABC&lt;/chargeto&gt;
          &lt;chargename&gt;GARY&lt;/chargename&gt;
      &lt;/Customer&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;ABC&lt;/chargeto&gt;
          &lt;chargename&gt;DAV&lt;/chargename&gt;
      &lt;/Customer&gt;
  &lt;/Customer_PO&gt;
  &lt;Customer_Falty&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;XYZ&lt;/chargeto&gt;
          &lt;chargename&gt;DAVIS&lt;/chargename&gt;
      &lt;/Customer&gt;
      &lt;Customer&gt;
          &lt;chargeto&gt;CDE&lt;/chargeto&gt;
          &lt;chargename&gt;GARY DAVIS&lt;/chargename&gt;
      &lt;/Customer&gt;
  &lt;/Customer_Falty&gt;
  &lt;/Root&gt;
  </code></pre>
  <p>Below is the XSLT which I wrote Initially to at least get the some details in the Output, but data is getting missed when the target is generated:</p>
  <pre><code>
      &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
      &lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns:msxsl=&quot;urn:schemas-microsoft-com:xslt&quot; xmlns:var=&quot;http://schemas.microsoft.com/BizTalk/2003/var&quot; exclude-result-prefixes=&quot;msxsl var&quot; version=&quot;1.0&quot; xmlns:ns0=&quot;http://Namespace&quot;&gt;
        &lt;xsl:output omit-xml-declaration=&quot;yes&quot; method=&quot;xml&quot; version=&quot;1.0&quot; /&gt;
        &lt;xsl:key use=&quot;chargeto&quot; match=&quot;/CustomerRecord/Customer&quot; name =&quot;groups&quot;/&gt;
        
        &lt;xsl:template match=&quot;/&quot;&gt;
          &lt;xsl:apply-templates select=&quot;/CustomerRecord&quot; /&gt;
        &lt;/xsl:template&gt;
        &lt;xsl:template match=&quot;/CustomerRecord&quot;&gt;
          &lt;Root&gt;
           &lt;xsl:for-each select=&quot;/CustomerRecord/Customer[generate-id(.)=generate-id(key('groups',chargeto))]&quot;&gt;      
              &lt;Customer_PO&gt;
                &lt;xsl:for-each select=&quot;key('groups',chargeto)&quot;&gt;
                &lt;Customer&gt;
                  &lt;chargeto&gt;
                    &lt;xsl:value-of select=&quot;CustomerRecord/chargeto/text()&quot; /&gt;
                  &lt;/chargeto&gt;
                  &lt;chargename&gt;
                    &lt;xsl:value-of select=&quot;CustomerRecord/chargename/text()&quot; /&gt;
                  &lt;/chargename&gt;
                &lt;/Customer&gt;
              &lt;/xsl:for-each&gt;  
              &lt;/Customer_PO&gt;
            &lt;/xsl:for-each&gt;
          &lt;/Root&gt;
        &lt;/xsl:template&gt;
      &lt;/xsl:stylesheet&gt;
  
  </code></pre>
  <p>Please find the explanation about the Expected Output</p>
  <p><code>&lt;Customer_PO&gt;</code>. Under this tag we will have all the <code>&lt;Customer&gt;</code> segments where all the <code>&lt;chargeto&gt;</code> fields are having duplicate  value</p>
  <p><code>&lt;Customer_Falty&gt;</code> Under this tag we will have all the <code>&lt;Customer&gt;</code> segment where all the <code>&lt;chargeto&gt;</code> field values are unique</p>