This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Sorting in descending order on the sum of a calculation
- From: "delay" <delay at pobox dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 28 Nov 2001 22:54:29 -0600
- Subject: [xsl] Sorting in descending order on the sum of a calculation
- References: <200111281509.KAA26382@biglist.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
I am rather new to xml and this list... I am trying to convert a stats
program I wrote into xml / xsl format and I am having trouble getting one of
the xsl style sheets to work. I need to sort the result of a sum performed
on an xml attribute in descending order by the total sum retrieved. I can
sum all of the like fields in a table for display but I am having trouble
getting it to then display in descending order.
Below is my current xml and xsl and the output it generates.
<referers>
<referer hits="1" page="/"
ref="http://academic.dt.uh.edu/~finch/links/links.htm" domain="dt.uh.edu"
keywords="no keywords found"/>
<referer hits="3" page="/" ref="http://www.rice.edu/houston/"
domain="rice.edu" keywords="no keywords found"/>
<referer hits="2" page="/calculator/converter.html" ref="bookmarks"
domain="" keywords="no keywords found"/>
<referer hits="3" page="/calculator/converter.html"
ref="http://sg.lycosasia.com/?query=++%2Bfree+%2Bcurrency+%2Bconverter"
domain="lycosasia.com" keywords=" free currency converter"/>
<referer hits="2" page="/cgi-bin/logscribe/makelog.pl"
ref="http://www.tradehere.com/calendar/calendar.html" domain="tradehere.com"
keywords="no keywords found"/>
<referer hits="1" page="/cgi-bin/logscribe/makelog.pl" ref="Blocked by
Norton" domain="" keywords="no keywords found"/>
</referers>
__________________________________________________________________
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:for-each select="//referers/referer">
<xsl:sort select="@page" order="ascending"/>
<xsl:if test="not(@page=preceding::referer/@page)">
<xsl:value-of
select="format-number(sum(//referers//referer[@page=current()/@page]/@hits),
'####00')"/>
-- <xsl:value-of select="@page"/><br/>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
___________________________________________________________________
Current output:
04 -- /
05 -- /calculator/converter.html
03 -- /cgi-bin/logscribe/makelog.pl
What I want the output to look like:
05 -- /calculator/converter.html
04 -- /
03 -- /cgi-bin/logscribe/makelog.pl
I have looked at a lot of examples in the FAQ (which has some great
examples) but I haven't been able to find anything for my particular case. I
tried sorting based on hits or trying to perform a second sort but didn't
have any success. I was wondering if anyone had any ideas as how to
accomplish this or could point me to an example.
Thanks,
-Delay
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list