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

RE: Sorting Nested Loops

Subject: RE: Sorting Nested Loops
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 9 Jul 2002 22:07:48 +0100
nested loops images
> I am having trouble
> getting the desired results when I try to sort by an
> attribute in a nested loop. I want to sort by the
> sequence attribute in ascending order. I get them back
> in this order
> 
> 1, 7, 8, 14, 3, 4, 9, 10, 5, 6, 11, 12, 2, 13

Well, you have divided the list into groups of four, and then you have
sorted each group of four, so this is precisely what you should expect.

If you want to sort the list before grouping it, the simplest way is to
do two passes. In the first pass, sort the entire list into a temporary
tree, in the second (using xx:node-set()) process this temporary tree
into groups of four.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> 
> Any ideas?
> 
> This is the xml
> 
> <?xml version="1.0" encoding="iso-8859-1" ?>
> <leadsite>
> <tabs>
> 
> 		<tab typeid="" sequence="1" active="1">
> 			<label>Tab 1</label>
> 			<url></url>
> 		</tab>
> 		<tab typeid="" sequence="14" active="1">
> 			<label>Tab 14</label>
> 			<url></url>
> 		</tab>
> 
> 				<tab typeid="" sequence="7" active="1">
> 			<label>Tab 7</label>
> 			<url></url>
> 		</tab>
> 		<tab typeid="" sequence="8" active="1">
> 			<label>Tab 8</label>
> 			<url></url>
> 		</tab>
> 				<tab typeid="" sequence="10" active="1">
> 			<label>Tab 10</label>
> 			<url></url>
> 		</tab>
> 		<tab typeid="" sequence="9" active="1">
> 			<label>Tab 9</label>
> 			<url></url>
> 		</tab>
> 		<tab typeid="" sequence="3" active="">
> 			<label>Tab 3</label>
> 			<url></url>
> 		</tab>
> 		<tab typeid="" sequence="4" active="1">
> 			<label>Tab 4</label>
> 			<url></url>
> 		</tab>
> 				<tab typeid="" sequence="5" active="1">
> 			<label>Tab 5</label>
> 			<url>/controlcenter/applications/tyler.asp</url>
> 		</tab>
> 		<tab typeid="" sequence="6" active="1">
> 			<label>Tab 6</label>
> 			<url></url>
> 		</tab>
> 				<tab typeid="" sequence="12" active="1">
> 			<label>Tab 12</label>
> 			<url>/controlcenter/applications/tyler.asp</url>
> 		</tab>
> 		<tab typeid="" sequence="11" active="1">
> 			<label>Tab 11</label>
> 			<url></url>
> 		</tab>
> 				<tab typeid="" sequence="13" active="1">
> 			<label>Tab 13</label>
> 			<url></url>
> 		</tab>
> 		<tab typeid="" sequence="2" active="1">
> 			<label>Tab 2</label>
> 			<url></url>
> 		</tab>
> 	</tabs>
> </leadsite>
> 
> This is the xsl
> 
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:template name="tabs" mode="tabs"
> match="leadsite/tabs">
> 	<xsl:for-each select="tab[position() mod 4 = 1]">
> 		
> 		<table width="100%" cellpadding="0" 
> cellspacing="0" border="0">
> 			<tr>
> 			<xsl:for-each select=". |
> following-sibling::tab[position() &lt; 4]">
> 			<xsl:sort select="@sequence" 
> data-type="number" />
> 			<xsl:call-template name="tabcells" />
> 			</xsl:for-each>
> 			</tr>
> 			<![CDATA[</tr>]]>
> 		</table>
> 	</xsl:for-each>
> 	</xsl:template>
> 
> 	<xsl:template name="tabcells">
> 		<td valign="Top" align="Left" width="8" 
> class="tabs" background="images/Agnt_J_Tabrig_Bg.Gif">
> 			<img height="15" src="images/Agnt_J_Tabrig.Gif"
> width="8" />
> 		</td>
> 		<td valign="Center" align="Middle" class="tabs"
> nowrap="yes">
> 			<xsl:variable name="url" select="url/." />
> 			<a href="{$url}">
> 				<xsl:value-of select="label/." />
> 			</a>
> 		</td>
> 		<td valign="Top" align="Right" width="8" 
> class="tabs" background="images/Agnt_J_Tablef.Gif">
> 			<img height="15" src="images/Agnt_J_Tablef.Gif"
> width="8" />
> 		</td>
> 		<td width="1">
> 			<img height="1" src="Dot.Gif" width="1" />
> 		</td>
> 	</xsl:template>
> 	
> </xsl:stylesheet>
> 
> 
> 	
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.