## Re: how to number on a grouped and sorted set?

 Subject: Re: how to number on a grouped and sorted set? From: Jeni Tennison Date: Sat, 4 Nov 2000 16:56:55 +0000
```Chad,

> I'm working with a group and sort set defined like this and just want to
> write the order (number - 1,2,3,etc.) into the last element called <rank>.
> How do I do that?

You have a xsl:for-each that iterates over the set of results that are
the first with a particular cuicode. Within that xsl:for-each, the
current node set is that list of results, so giving the position() of
the particular 'result' element within that set will number them
sequentially, which I think is what you were after. i.e.:

<rank><xsl:value-of select="position()" /></rank>

xsl:number is best used for numbering items according to their
position in the source tree rather than the result tree.  You *could*
use it in this situation, by changing the counted nodes to be the
result elements that are first with a particular cuicode, but that's a
bit complicated when you can use position() instead.

I hope you don't mind me just commenting on another bit of the
stylesheet: it's probably what you were after, but just to make sure:
the first sort you're doing is on:

This will sum the values of *all* the bitmask children of the results
with the same cuicode.  I just wanted to check that this was what you
were after, rather than the sum of the bitmask children of the
result elements that are actually being sorted.

The other sorts will sort on the value of (a) the count and (b) the
offset elements that appear first as children of the results with the
same cuicode. That means that if the first result element with a
particular cuicode doesn't have a 'count' or 'offset' child, then it
will try to sort on the 'count' or 'offset' of the next result element
with the same cuicode, unless it doesn't have one, in which case it'll
move onto the next and so on.

It's very possible that this is the behaviour you're after, but it's
equally likely that you actually were only interested in the values
for the first result, or that you can guarantee that the first result
has 'count' or 'offset' children.  If that's the case, rather than
refer to the key again, just use:

<xsl:sort data-type="number" select="count" order="descending" />
<xsl:sort data-type="number" select="offset" order="descending" />

I hope that this helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

```