title: Duplicate in key (Muenchian Grouping)
body: <p>it may sound strange, but is it the case that, for example, if we group it based on 3 things and also want to see a recurrence of a certain element in the key? Can anyone give a simple example if this exists? Although I searched for previous solutions, I only found one where duplicates were deleted.</p>
  <p>I finally have my example.</p>
  <p>My XML:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;invoices&gt;
      &lt;invoice buyer=&quot;Company_1&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_1&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;1878.95&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_1&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_1&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;0.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_1&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;5678&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_1&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;1900.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_1&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;5678&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_1&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;0.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_2&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_1&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;1900.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_2&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_2&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;2700.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_2&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_3&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;500.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_3&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_1&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;0.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_3&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_2&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;100.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
      &lt;invoice buyer=&quot;Company_3&quot;&gt;
          &lt;invoicenumbers&gt;
              &lt;invoicenumber name=&quot;1234&quot;/&gt;
          &lt;/invoicenumbers&gt;
          &lt;cost&gt;
              &lt;COSTGROUP name=&quot;Group_3&quot;/&gt;
          &lt;/cost&gt;
          &lt;amounts&gt;
              &lt;amount localamount=&quot;5000.00&quot;/&gt;
          &lt;/amounts&gt;
      &lt;/invoice&gt;
  &lt;/invoices&gt;
  </code></pre>
  <p>My XSLT:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns=&quot;urn:schemas-microsoft-com:office:spreadsheet&quot; xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot; xmlns:x=&quot;urn:schemas-microsoft-com:office:excel&quot; xmlns:ss=&quot;urn:schemas-microsoft-com:office:spreadsheet&quot; xmlns:html=&quot;http://www.w3.org/TR/REC-html40&quot;&gt;
      &lt;xsl:output method=&quot;xml&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot;/&gt;
  
      &lt;xsl:key name=&quot;Muenchian_Grouping&quot; 
          match=&quot;/invoices/invoice&quot;
          use=&quot;concat(@buyer, '|', invoicenumbers/invoicenumber/@name)&quot;/&gt;
      
      &lt;xsl:key name=&quot;Muenchian_Grouping_by_costgroup&quot; 
          match=&quot;/invoices/invoice&quot;
          use=&quot;concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', cost/COSTGROUP/@name)&quot;/&gt;  
  
      &lt;xsl:template match=&quot;/&quot;&gt;
          &lt;Workbook&gt;
              &lt;Worksheet ss:Name=&quot;Report&quot;&gt;
                  &lt;xsl:call-template name=&quot;ws_table&quot;/&gt;
              &lt;/Worksheet&gt;
          &lt;/Workbook&gt;
      &lt;/xsl:template&gt;
  
  
      &lt;xsl:template name=&quot;ws_table&quot;&gt;
          &lt;Table&gt;
              &lt;xsl:call-template name=&quot;columns&quot;/&gt;
              &lt;xsl:call-template name=&quot;columnHeader&quot;/&gt;
              
              &lt;xsl:apply-templates select=&quot;invoices/invoice[generate-id() = generate-id(key('Muenchian_Grouping', 
                  concat(@buyer, '|', invoicenumbers/invoicenumber/@name))[1])]&quot; mode=&quot;invoices&quot;/&gt;
          &lt;/Table&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name=&quot;columns&quot;&gt;
          &lt;Column ss:Width=&quot;269.25&quot;/&gt;
          &lt;Column ss:Width=&quot;218.25&quot;/&gt;
          &lt;Column ss:Width=&quot;291.75&quot;/&gt;
          &lt;Column ss:Width=&quot;276.75&quot;/&gt;
          &lt;Column ss:Width=&quot;276.75&quot;/&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name=&quot;columnHeader&quot;&gt;
          &lt;Row&gt;
              &lt;!-- buyer --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;buyer&lt;/Data&gt;
              &lt;/Cell&gt; 
              &lt;!-- invoicenumber --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;invoicenumber&lt;/Data&gt;
              &lt;/Cell&gt;
              &lt;!-- Group1_localamount --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;Group1_localamount&lt;/Data&gt;
              &lt;/Cell&gt;
              &lt;!-- Group1_localamount --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;Group2_localamount&lt;/Data&gt;
              &lt;/Cell&gt;
              &lt;!-- Group1_localamount --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;Group3_localamount&lt;/Data&gt;
              &lt;/Cell&gt;
          &lt;/Row&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match=&quot;invoice&quot; mode=&quot;invoices&quot;&gt;
          
          &lt;xsl:variable name=&quot;Group1_data&quot; select=&quot;key('Muenchian_Grouping_by_costgroup', 
              concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', 'Group_1'))&quot;/&gt;
          
          &lt;xsl:variable name=&quot;Group2_data&quot; select=&quot;key('Muenchian_Grouping_by_costgroup', 
              concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', 'Group_2'))&quot;/&gt;
          
          &lt;xsl:variable name=&quot;Group3_data&quot; select=&quot;key('Muenchian_Grouping_by_costgroup', 
              concat(@buyer, '|', invoicenumbers/invoicenumber/@name, '|', 'Group_3'))&quot;/&gt;
          
          &lt;Row&gt;
              &lt;!-- buyer - when group1 is not exists --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;
                      &lt;xsl:value-of select=&quot;$Group1_data/@buyer | $Group2_data/@buyer | $Group3_data/@buyer&quot;/&gt;
                  &lt;/Data&gt;
              &lt;/Cell&gt;
              &lt;!-- invoicenumber - when group1 is not exists --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;
                      &lt;xsl:value-of select=&quot;$Group1_data/invoicenumbers/invoicenumber/@name | $Group2_data/invoicenumbers/invoicenumber/@name | $Group3_data/invoicenumbers/invoicenumber/@name&quot;/&gt;
                  &lt;/Data&gt;
              &lt;/Cell&gt;
              &lt;!-- Group1_localamount --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;
                      &lt;xsl:value-of select=&quot;$Group1_data/amounts/amount/@localamount&quot;/&gt;
                  &lt;/Data&gt;
              &lt;/Cell&gt;
              &lt;!-- Group1_localamount --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;
                      &lt;xsl:value-of select=&quot;$Group2_data/amounts/amount/@localamount&quot;/&gt;
                  &lt;/Data&gt;
              &lt;/Cell&gt;
              &lt;!-- Group1_localamount --&gt;
              &lt;Cell&gt;
                  &lt;Data ss:Type=&quot;String&quot;&gt;
                      &lt;xsl:value-of select=&quot;$Group3_data/amounts/amount/@localamount&quot;/&gt;
                  &lt;/Data&gt;
              &lt;/Cell&gt;
              
          &lt;/Row&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>So as you can see in the XML the &quot;Company_1&quot; has a duplicate value at &quot;invoicenumber name=&quot;1234&quot;&quot; and at &quot;invoicenumber name=&quot;5678&quot;&quot;, and the question is how can i see both in the output excel file?</p>
  <p>EDIT:
  Expected result:
  <a href="https://i.stack.imgur.com/9zpOJ.png" rel="nofollow noreferrer">enter image description here</a></p>