Re: [xsl] sorted table elements

Subject: Re: [xsl] sorted table elements
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Fri, 04 Oct 2002 12:02:46 +0200
Hello Saverio,

you are on the right way, but it's a dead-end street ;-)

The problem: While you sort the elements and bring them into a new order, following-sibling still uses document order, not the order after the sorting. You must store the sorting in a variable:

<xsl:variable name="sortedElements">
    <xsl:for-each select="*">
        <xsl:sort data-type="text" select="name()"/>
        <xsl:copy-of select="."/>

But now you have a Result Tree Fragment (RTF) in your variable, no longer a node set, on which you can operate. You have to use an extension function zo convert it back to a node set. For this you can use EXSLT or vendor specific extension functions:

<xsl:variable name="sortedElementsNodeSet" select="exslt:node-set($sortedElements)/*"/>

Now preceding-sibling or following-sibling works correctly:

<xsl:for-each select="$sortedElementsNodeSet[position() mod 4 = 1">
    <xsl:for-each select=".|following-sibling::node()[position() &lt; 4]">

Hope this works, it's untested ;-)



Saverio Perugini wrote:

I'd like to produce a 4 column HTML table where each <td>
element is alphabetically sorted from cell 1,1 to cell n,4
(where n is the required number of rows).

The following is an attempt:

   <xsl:for-each select="*[position() mod 4 = 1]">
      <xsl:sort data-type="text" select="name()"/>
            <xsl:for-each select=".|following-sibling::node()[position() &lt; 4]">

This code only sorts all the *[position() mod 4 = 1] elements.
Therefore, only column one is sorted, whereas I wanted the entire
table (an linear list from cell 1,1 to cell n,4 sorted).  Can this be done?

Thank You and Best Regards,

S. Perugini


System Development
Fon  +49(0)341-979-7419
Fax  +49(0)341-979-7409

VIRBUS hat jetzt als erster deutscher Softwarehersteller die Zertifizierung für den 3D Secure-Authentifizierungsstandard "Verified by Visa" erhalten. Details unter

XSL-List info and archive:

Current Thread