[xsl] group-by sorting and paging problem...

Subject: [xsl] group-by sorting and paging problem...
From: Robert Wilkins <wilkins.robert@xxxxxxxxxxx>
Date: Fri, 24 Nov 2006 21:19:13 -0500
I've been struggling with this for days. The problem seems simple,
but I've had no luck...Here's what I'm trying to do:

  -  Group the <msgblocks> by attribute 'id'
  -  Use the current grouping id (@id) to sort the data
  - Arrange the data I want to extract from each sorted <msgblock>
(errnum and message) into a series of balanced 4 column tables
limited to a maximum of x number of
     rows, based on the value of the global param $cols
  - Write (or page) each table to a result-document

A subset of the xml looks like this:

  <msgblock id="2000">
    <message> No message</message>

  <msgblock id="2001">
    <message> "Row not found"</message>

  <msgblock id="2002">
    <message> "Value truncated"</message>

  <msgblock id="2003">
    <message> "Using temporary table"</message>

  <msgblock id="2004">
    <message> "Invalid data conversion"</message>

  <msgblock id="2559">
    <message> "A row could not be converted to the new schema

  <msgblock id="2532">
    <message> "Invalid data conversion: NULL was inserted for column
'%1' on line %2."</message>

  <msgblock id="2005">
    <message> "Row has been updated since last time read"</message>

  <msgblock id="2006">
    <message> "Procedure has completed"</message>

  <msgblock id="2007">
    <message> "Value for column '%1' in table '%2' has changed"</

  <msgblock id="2008">
    <message> "Statement cannot be executed"</message>

  <msgblock id="2530">
    <message> "Database created without any schema"</message>

  <msgblock id="2009">
    <message> "Warning"</message>

  <msgblock id="2011">
    <message> "Unable to start database server"</message>

  <msgblock id="2702">
    <message> "Unable to start database server: Server fatal error"</

  <msgblock id="2012">
    <message> "Invalid database server command line"</message>


Grouping and sorting the <msgblock> nodes is necessary because the @id's are not always in the right sequence. I can group and sort them properly with this snippet:

<xsl:for-each-group select="msgblock" group-by="@id">
                <xsl:sort select="current-grouping-key()"/>
		<for-each select=current-group()/>
			<xsl:value-of select =errnum/>
			<xsl:vale-of select=message/>
		</for each>

I can limit the number of table items by testing the global
parameters $start-index (1) and $group-size (40) with something like

        <xsl:if test="position() &gt;= $start-index
            and position() &lt;= $group-size">

(Thank you, Ms. Tennison)

I can see the logic in Micheal Kay's examples (town-by-columns, town-
by-rows, towns-sorted-by-rows) in the XSLT 2.0 Programmer's
Reference. But I can't seem to put them all together. (I always seem
to end up dividing by zero).  I seemed close a couple of times, but
I've had no luck. In fact, I seem to be going backwards.

Does anyone know how to do this?

Thanks in advance....

------- bob wilkins ------

Current Thread