Re: [xsl] Performance degraded with grouping and sorting.

Subject: Re: [xsl] Performance degraded with grouping and sorting.
From: Geert Josten <Geert.Josten@xxxxxxxxxxx>
Date: Sat, 30 Oct 2004 11:50:19 +0200
Bhupendra, (and others,)

Why are you using a double for-each loop?

I would expect you use it to output a separator of any kind (title, hr, or anything else) between
the groups, but you aren't as far as I can see. In that case, I would expect it would be sufficient
to add a sort key on ACCT_NBR to group to that element. Note that the order of the sort keys
influences the result.

Also, I see you use things like *[name()=$paramSortKey], though only in the outer loop. Still, it
could improve performance to duplicate the sorting code and wrap things up in a choose, so that you
can replace the expression by just the element name.

Personally, I still prefer a multistep sorting and grouping algorithm. If you can assertain that
values are sorted already, grouping might become a lot easier in XSLT 1. I used Cocoon to build a
multistep process, where I first sort and later group. The grouping algoritms uses an index for
retrieving the first of a group, but not with the Munchian Method:

  <xsl:key name="first-group-values" match="item[not(preceding-sibling::*) or (@group !=
preceding-sibling::*[1]/@group)]" use="'all'" />
  <xsl:key name="values-by-group" match="item" use="@group" />

  <xsl:for-each select="key('first-group-values', 'all')">
    <!-- output separator -->
    <xsl:for-each select="key('values-by-group', @group)">
      <!-- output item -->
    </xsl:for-each>
  </xsl:for-each>

Note that I use a group attribute I determined in an earlier step to base the grouping on. This way,
the grouping algorithm doesn't change when I want to group on something else. (Separation of Concerns!)

Anyone who would like to do some performance tests on this?

Grtz,
Geert

Current Thread