ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
[xsl] group-by sorting and paging problem...
by Robert Wilkins other posts by this author
Nov 24 2006 6:19PM messages near this date
RE: [xsl] counting nodes question | [xsl] Transform inline-block type elements to block-level elements
& XSLT 
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:

<messages> 
   <msgblock id="2000"> 
     <msg-num> 0</msg-num>
     <errnum> 2000</errnum>
     <message>  No message</message>
   </msgblock> 

   <msgblock id="2001"> 
     <msg-num> 100</msg-num>
     <errnum> 2001</errnum>
     <message>  "Row not found"</message>
   </msgblock> 

   <msgblock id="2002"> 
     <msg-num> 101</msg-num>
     <errnum> 2002</errnum>
     <message>  "Value truncated"</message>
   </msgblock> 

   <msgblock id="2003"> 
     <msg-num> 102</msg-num>
     <errnum> 2003</errnum>
     <message>  "Using temporary table"</message>
   </msgblock> 

   <msgblock id="2004"> 
     <msg-num> 103</msg-num>
     <errnum> 2004</errnum>
     <message>  "Invalid data conversion"</message>
   </msgblock> 

   <msgblock id="2559"> 
     <msg-num> 130</msg-num>
         <errnum> 2559</errnum>
     <message>  "A row could not be converted to the new schema  
format"</message> 
   </msgblock> 

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

   <msgblock id="2005"> 
     <msg-num> 104</msg-num>
     <errnum> 2005</errnum>
     <message>  "Row has been updated since last time read"</message>
   </msgblock> 

   <msgblock id="2006"> 
     <msg-num> 105</msg-num>
         <errnum> 2006</errnum>
     <message>  "Procedure has completed"</message>
   </msgblock> 

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

   <msgblock id="2008"> 
     <msg-num> 111</msg-num>
     <errnum> 2008</errnum>
     <message>  "Statement cannot be executed"</message>
   </msgblock> 

   <msgblock id="2530"> 
     <msg-num> 123</msg-num>
     <errnum> 2530</errnum>
     <message>  "Database created without any schema"</message>
   </msgblock> 

   <msgblock id="2009"> 
     <msg-num> 200</msg-num>
     <errnum> 2009</errnum>
     <message>  "Warning"</message>
   </msgblock> 

   <msgblock id="2011"> 
     <msg-num> 80</msg-num>
     <errnum> 2011</errnum>
     <message>  "Unable to start database server"</message>
   </msgblock> 

   <msgblock id="2702"> 
     <msg-num> 1033</msg-num>
     <errnum> 2702</errnum>
     <message>  "Unable to start database server: Server fatal error"</ 
message> 
   </msgblock> 

   <msgblock id="2012"> 
     <msg-num> 81</msg-num>
     <errnum> 2012</errnum>
     <message>  "Invalid database server command line"</message>
   </msgblock> 

</messages> 


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> 
	<for-each-group> 

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

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

(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 ------


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@[...].com> 
--~--

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved