title: XSLT 1.0: grouping one value to many values - use of keys?
body: <p>I have the following simplified XML structure:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;
  &lt;DESADV&gt;
  &lt;M_DESADV&gt;
      &lt;G_SG10&gt;
          &lt;G_SG13&gt;
              &lt;S_GIN&gt;
                  &lt;id&gt;GIN&lt;/id&gt;
                  &lt;D_7405_6&gt;BJ&lt;/D_7405_6&gt;
                  &lt;C_C208_2&gt;
                      &lt;D_7402_8&gt;373500699550026556&lt;/D_7402_8&gt;
                  &lt;/C_C208_2&gt;
              &lt;/S_GIN&gt;
          &lt;/G_SG13&gt;
      &lt;/G_SG10&gt;
      &lt;G_SG10&gt;
          &lt;G_SG17&gt;
              &lt;S_PIA&gt;
                  &lt;id&gt;PIA&lt;/id&gt;
                  &lt;D_4347&gt;1&lt;/D_4347&gt;
                  &lt;C_C212_2&gt;
                      &lt;D_7140_2&gt;110005&lt;/D_7140_2&gt;
                      &lt;D_7143_4&gt;SA&lt;/D_7143_4&gt;
                  &lt;/C_C212_2&gt;
              &lt;/S_PIA&gt;
          &lt;/G_SG17&gt;
      &lt;/G_SG10&gt;
      &lt;G_SG10&gt;
          &lt;G_SG17&gt;
              &lt;S_PIA&gt;
                  &lt;id&gt;PIA&lt;/id&gt;
                  &lt;D_4347&gt;1&lt;/D_4347&gt;
                  &lt;C_C212_2&gt;
                      &lt;D_7140_2&gt;123456&lt;/D_7140_2&gt;
                      &lt;D_7143_4&gt;SA&lt;/D_7143_4&gt;
                  &lt;/C_C212_2&gt;
              &lt;/S_PIA&gt;
          &lt;/G_SG17&gt;
      &lt;/G_SG10&gt;
      &lt;G_SG10&gt;
          &lt;G_SG13&gt;
              &lt;S_GIN&gt;
                  &lt;id&gt;GIN&lt;/id&gt;
                  &lt;D_7405_6&gt;BJ&lt;/D_7405_6&gt;
                  &lt;C_C208_2&gt;
                      &lt;D_7402_8&gt;3735009999999999&lt;/D_7402_8&gt;
                  &lt;/C_C208_2&gt;
              &lt;/S_GIN&gt;
          &lt;/G_SG13&gt;
      &lt;/G_SG10&gt;
      &lt;G_SG10&gt;
          &lt;G_SG17&gt;
              &lt;S_PIA&gt;
                  &lt;id&gt;PIA&lt;/id&gt;
                  &lt;D_4347&gt;1&lt;/D_4347&gt;
                  &lt;C_C212_2&gt;
                      &lt;D_7140_2&gt;632154&lt;/D_7140_2&gt;
                      &lt;D_7143_4&gt;SA&lt;/D_7143_4&gt;
                  &lt;/C_C212_2&gt;
              &lt;/S_PIA&gt;
          &lt;/G_SG17&gt;
      &lt;/G_SG10&gt;
      &lt;G_SG10&gt;
          &lt;G_SG17&gt;
              &lt;S_PIA&gt;
                  &lt;id&gt;PIA&lt;/id&gt;
                  &lt;D_4347&gt;1&lt;/D_4347&gt;
                  &lt;C_C212_2&gt;
                      &lt;D_7140_2&gt;887796&lt;/D_7140_2&gt;
                      &lt;D_7143_4&gt;SA&lt;/D_7143_4&gt;
                  &lt;/C_C212_2&gt;
              &lt;/S_PIA&gt;
          &lt;/G_SG17&gt;
      &lt;/G_SG10&gt;
  &lt;/M_DESADV&gt;
  &lt;/DESADV&gt;
  </code></pre>
  <p>I need to do a mapping so I get the following XML output:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;list&gt;
  &lt;number&gt;373500699550026556 110005&lt;/number&gt;
  &lt;number&gt;373500699550026556 123456&lt;/number&gt;
  &lt;number&gt;3735009999999999 632154&lt;/number&gt;
  &lt;number&gt;3735009999999999 887796&lt;/number&gt;
  &lt;/list&gt;
  </code></pre>
  <p>I am having trouble getting that output though. I have the following XSLT that I though would work:</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;
  version=&quot;1.0&quot;&gt;
  
  &lt;xsl:template match=&quot;text()&quot;/&gt;
  
  &lt;xsl:template match=&quot;/&quot;&gt;
      &lt;list&gt;
      &lt;xsl:apply-templates/&gt;
      &lt;/list&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match=&quot;M_DESADV&quot;&gt;
      
      &lt;xsl:for-each select=&quot;G_SG10/G_SG17/S_PIA/C_C212_2[D_7143_4='SA']/D_7140_2&quot;&gt;
          &lt;number&gt;
              &lt;xsl:value-of select=&quot;concat(
                  parent::C_C212_2/parent::S_PIA/parent::G_SG17/parent::G_SG10/parent::M_DESADV
                  /G_SG10/G_SG13/S_GIN[D_7405_6='BJ']/C_C208_2/D_7402_8,' ',
                  .)
                  &quot;/&gt;
          &lt;/number&gt;
      &lt;/xsl:for-each&gt;
  &lt;/xsl:template&gt;
  
  
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>But my output looks like this which is not what I expect:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;list&gt;
  &lt;number&gt;373500699550026556 110005&lt;/number&gt;
  &lt;number&gt;373500699550026556 123456&lt;/number&gt;
  &lt;number&gt;373500699550026556 632154&lt;/number&gt;
  &lt;number&gt;373500699550026556 887796&lt;/number&gt;
  &lt;/list&gt;
  </code></pre>
  <p>Can this be solved with Muenchian Grouping? I tried setting up a key but it either selects
  &quot;D_7402_8&quot; or only &quot;D_7140_2&quot;.</p>