I got task to modify tool made by some other guy who left the company some time ago. Last thing left to do is the grouping part of XML by date. Every example I found works with XML with attributes so it's not really that helpful.
My XML does not have single attribute and its structure is something like this:
<report>
<clientInfo>
...
</clientInfo>
<bills>
<bill>
<section>
<dateSegment>20-07-1990</dateSegment>
<money>100</money>
<days>9</days>
</section>
<section>
<dateSegment>20-08-1990</dateSegment>
<money>130</money>
<days>4</days>
</section>
<section>
<dateSegment>20-09-1990</dateSegment>
<money>110</money>
<days>5</days>
</section>
</bill>
<bill>
<section>
<dateSegment>20-07-1990</dateSegment>
<money>230</money>
<days>11</days>
</section>
<section>
<dateSegment>20-10-1990</dateSegment>
<money>210</money>
<days>3</days>
</section>
</bill>
...
</bills>
...
</report>
I have to group by same date and sum up per each group. I tried writing template according to how to apply group by on xslt elements post but it's far from working as intended.
<xsl:key name="by_date" match="section" use="@dateSegment" />
<xsl:template name="test">
<xsl:element name="AllSections">
<xsl:for-each-group select="*" group-by="@dateSegment">
<xsl:element name="dateSegment">
<xsl:attribute name="value">
<xsl:value-of select="@dateSegment" />
</xsl:attribute>
<xsl:for-each select="current-group()">
<xsl:element name="section">
<xsl:element name="money"><xsl:value-of select="@money" /></xsl:element>
<xsl:element name="days"><xsl:value-of select="@days" /></xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each-group>
</xsl:element>
</xsl:template>
Tried calling it with <xsl:call-template name="test"/>
but nothing happens, result is null.
Expected output:
Either
<dateSegment value="20-07-1990">
<section>
<money>100</money>
<days>9</days>
</section>
<section>
<money>230</money>
<days>11</days>
</section>
</dateSegment>
<dateSegment value="20-08-1990">
<section>
<money>130</money>
<days>4</days>
</section>
</dateSegment>
...
or
<dateSegment>
<money>340</money>
<days>11</days> (max value from <days> in same section)
</dateSegment>
<dateSegment>
<money>130</money>
<days>4</days>
</section>
</dateSegment>
Would be helpful to assign that XML to variable so I could do stuff with it.
Alrdy asked everyone I could but none of us works with such things and no one was able to help me out.
Any idea how to do it?