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.
XML data:
<table>
<row>
<month>03</month>
<year>2016</year>
<Id>10101</Id>
<Number>1</Number>
<code>A2004</code>
</row>
<row>
<month>03</month>
<year>2016</year>
<type>A</type>
<Id>10101</Id>
<Number>2</Number>
<code>A2004</code>
</row>
<row>
<month>04</month>
<year>2015</year>
<Id>10122</Id>
<Number>1</Number>
<code>A2004</code>
</row>
</table>
I am trying to group this xml on the ID level and the numbers within it.
<test>
<xsl:for-each-group select="$table" group-by="Id">
<xsl:variable name="var2_resultof_group_items" as="item()+" select="current-group()"/>
</xsl:variable>
<row>
<xsl:attribute name="Id">
<xsl:value-of select="normalize-space(current-grouping-key())"/>
</xsl:attribute>
<xsl:for-each select="$var2_resultof_group_items">
<xsl:attribute name="month">
<xsl:value-of select="month"/>
</xsl:attribute>
</xsl:for-each>
<xsl:for-each select="$var2_resultof_group_items">
<xsl:attribute name="year">
<xsl:value-of select="year"/>
</xsl:attribute>
</xsl:for-each>
<xsl:for-each-group select="$var2_resultof_group_items" group-by="Number">
<xsl:variable name="var1_resultof_group_items" as="item()+" select="current-group()"/>
<line>
<xsl:attribute name="number" select="current-grouping-key()"/>
<xsl:for-each select="$var1_resultof_group_items">
<xsl:attribute name="code">
<xsl:value-of select="code"/>
</xsl:attribute>
</xsl:for-each>
</line>
</xsl:for-each-group>
</row>
</xsl:for-each-group>
</test>
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
<test>
<row Id="10101" month="03" year="2016">
<line Number="1" code="A2004"/>
<line Number="2" code="A2004"/>
</row>
<row Id="10122" month="04" year="2015">
<line Number="1" code="A2004"/>
</row>
</test>
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:
<test>
<row Id="10101" month="03" year="2016">
<line Number="1" code="A2004"/>
</row>
<row Id="10101" month="03" year="2016">
<line Number="2" code="A2004"/>
</row>
<row Id="10122" month="04" year="2015">
<line Number="1" code="A2004"/>
</row>
</test>