[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Sorting and grouping

Subject: Re: Sorting and grouping
From: ronald heller <ronald@xxxxxxxxxxx>
Date: Tue, 30 Oct 2001 12:04:44 +0100
test position mod sort
sorry I mistakenly used following-sibling in my code example, here an update:

Make sure you first order your items, the next step is breaking it up in groups of say 5.
Don't try to start with grouping before sorting, that won't work!

I now first sort according to the at attribute, then I test within item wich position it has within the sorted items list.
is position mod $group is 1 than it's the first of the group, if it's zero, it's the last.

otherwise it's something in between.

Hope this helps.


<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output method="xml" encoding="Windows-1252" />

<xsl:param name="group">5</xsl:param> <!-- grouping size-->

<xsl:variable name="items" select="count(//item)"/> <!-- total number of items-->

   <xsl:template match="list">
	    <xsl:apply-templates select="item">
	    	<xsl:sort select="@at" order="ascending"/>

<xsl:template match="item">

<xsl:when test="position() mod $group =1">
<xsl:comment>Begin new group</xsl:comment>
<p><xsl:value-of select="position()"/> - <xsl:apply-templates/></p>
<xsl:when test="position() mod $group =0">
<p><xsl:value-of select="position()"/> - <xsl:apply-templates/></p>
<xsl:comment>End group</xsl:comment>
<xsl:when test="not(position() mod $group =0) and position() = $items"> <!-- last item in sorted list-->
<p><xsl:value-of select="position()"/> - <xsl:apply-templates/></p>
<xsl:comment>End group</xsl:comment>
<p><xsl:value-of select="position()"/> - <xsl:apply-templates/></p>





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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.