[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: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 09 Jul 2002 22:32:44 +0200
|
In theory you are missing a <xsl:sort/> at the outer <xsl:for-each/>.
You are only sorting the tab elements in one line.
But even the "global" sorting would not work like you expect it, because
of the use of following-sibling-axis, which uses not the sorted tab
elements, but the document order of them. So there is no way to do this
in pure XSLT.
If it is possible for you to use extension functions I suggest to use
node-set(). You store the tabs sorted in a variable and work on this
variable in the same as you did it until now. But whe creating the
variable, it contains a Result Tree Fragment, that yuo have to convert
back to a node set.
<xsl:varaible name="sorted-tabs-rtf">
<xsl:for-each select="tab">
<xsl:sort select="@sequence" data-type="number"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="sorted-tabs-nodeset"
select="xx:node-set($sorted-tabs-rtf)"/>
<xsl:for-each select="$sorted-tabs-nodeset/tab[position() mod 4 = 1]">
... and so on ...
For more information, you can read
http://www.w3.org/TR/xslt#section-Result-Tree-Fragments.
Regards,
Joerg
Tyler Queen wrote:
I appologize for all the spam but I included the wrong
code in the last mailing. Sorry I'm having a off day.
Last try.
I posted this question earlier, but I did'nt include
enough info. I hope this helps. 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
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() < 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|