title: How to use group-by functionality from XSLT 2.0 in XSLT 1.0?
body: <p>I am trying to use the group-by functionality in XSLT 2.0 in XSLT 1.0. I have code working in XSLT 2.0 but my processor does not handle xslt 2.0. So i need some help using the group-by function in xslt 1.0.</p>
  
  <p>XML data:</p>
  
  <pre><code>              &lt;table&gt;
                  &lt;row&gt;
                      &lt;month&gt;03&lt;/month&gt;
                      &lt;year&gt;2016&lt;/year&gt;
                      &lt;Id&gt;10101&lt;/Id&gt;
                      &lt;Number&gt;1&lt;/Number&gt;
                      &lt;code&gt;A2004&lt;/code&gt;
                  &lt;/row&gt;
                  &lt;row&gt;
                      &lt;month&gt;03&lt;/month&gt;
                      &lt;year&gt;2016&lt;/year&gt;
                      &lt;type&gt;A&lt;/type&gt;
                      &lt;Id&gt;10101&lt;/Id&gt;
                      &lt;Number&gt;2&lt;/Number&gt;
                      &lt;code&gt;A2004&lt;/code&gt;
                  &lt;/row&gt;
                  &lt;row&gt;
                      &lt;month&gt;04&lt;/month&gt;
                      &lt;year&gt;2015&lt;/year&gt;
                      &lt;Id&gt;10122&lt;/Id&gt;
                      &lt;Number&gt;1&lt;/Number&gt;
                      &lt;code&gt;A2004&lt;/code&gt;
                  &lt;/row&gt;
              &lt;/table&gt;
  </code></pre>
  
  <p>I am trying to group this xml on the ID level and the numbers within it.</p>
  
  <pre><code>            &lt;test&gt;
                  &lt;xsl:for-each-group select="$table" group-by="Id"&gt;
                      &lt;xsl:variable name="var2_resultof_group_items" as="item()+" select="current-group()"/&gt;
                      &lt;/xsl:variable&gt;
                      &lt;row&gt;
                          &lt;xsl:attribute name="Id"&gt;
                              &lt;xsl:value-of select="normalize-space(current-grouping-key())"/&gt;
                          &lt;/xsl:attribute&gt;
                          &lt;xsl:for-each select="$var2_resultof_group_items"&gt;
                              &lt;xsl:attribute name="month"&gt;
                                  &lt;xsl:value-of select="month"/&gt;
                              &lt;/xsl:attribute&gt;
                          &lt;/xsl:for-each&gt;
                          &lt;xsl:for-each select="$var2_resultof_group_items"&gt;
                              &lt;xsl:attribute name="year"&gt;
                                  &lt;xsl:value-of select="year"/&gt;
                              &lt;/xsl:attribute&gt;
                          &lt;/xsl:for-each&gt;
                          &lt;xsl:for-each-group select="$var2_resultof_group_items" group-by="Number"&gt;
                              &lt;xsl:variable name="var1_resultof_group_items" as="item()+" select="current-group()"/&gt;
                              &lt;line&gt;
                                  &lt;xsl:attribute name="number" select="current-grouping-key()"/&gt;
                                  &lt;xsl:for-each select="$var1_resultof_group_items"&gt;
                                      &lt;xsl:attribute name="code"&gt;
                                          &lt;xsl:value-of select="code"/&gt;
                                      &lt;/xsl:attribute&gt;
                                  &lt;/xsl:for-each&gt;
                              &lt;/line&gt;
                          &lt;/xsl:for-each-group&gt;
                      &lt;/row&gt;
                  &lt;/xsl:for-each-group&gt;
              &lt;/test&gt;
  </code></pre>
  
  <p>This is the output i am getting with my xslt 2.0 code (desired output) but i am not sure how to perform this using xslt 1.0</p>
  
  <pre><code>            &lt;test&gt;
                  &lt;row Id="10101" month="03" year="2016"&gt;
                      &lt;line Number="1" code="A2004"/&gt;
                      &lt;line Number="2" code="A2004"/&gt;
                  &lt;/row&gt;
                  &lt;row Id="10122" month="04" year="2015"&gt;
                      &lt;line Number="1" code="A2004"/&gt;
                  &lt;/row&gt;
              &lt;/test&gt;
  </code></pre>
  
  <p>I am able to use XLST 1.0 to get till the output below, but i am not sure how to implement grouping of ID and then the Numbers within it:</p>
  
  <pre><code>            &lt;test&gt;
                  &lt;row Id="10101" month="03" year="2016"&gt;
                      &lt;line Number="1" code="A2004"/&gt;
                  &lt;/row&gt;
                  &lt;row Id="10101" month="03" year="2016"&gt;
                      &lt;line Number="2" code="A2004"/&gt;
                  &lt;/row&gt;
                  &lt;row Id="10122" month="04" year="2015"&gt;
                      &lt;line Number="1" code="A2004"/&gt;
                  &lt;/row&gt;
              &lt;/test&gt;
  </code></pre>