xsl-list
[Top] [All Lists]

Re: Alternate sort order of subelements based on previous parent element

2005-09-01 00:13:54
Hi,
Tempore 03:00:25, die 09/01/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Philipp Kursawe 
<LukeSky77(_at_)gmx(_dot_)net>:

I have run into a problem solving the following sophisticated (at least for
me) task:
There is a list of items each containing two nodes "row" and "col". First
the list has to be ordered ASCENDING by "rows". Next step is to sort the
list items of each "row" by its "col" node where the ordering direction
changes when the row is different to the previous.

I guess the easiest way is to group the 'item' elements by row and then 
alternate their sort order:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml" indent="yes"/>

<xsl:key name="item" match="item" use="@row"/>

<xsl:template match="items">
<xsl:copy>
<xsl:for-each select="item[generate-id(key('item',@row))=generate-id()]">
        <xsl:sort select="@row" data-type="number"/>
        <xsl:variable name="order">
                <xsl:choose>
                        <xsl:when test="position() mod 2=0">ascending</xsl:when>
                        <xsl:otherwise>descending</xsl:otherwise>
                </xsl:choose>
        </xsl:variable>
        <xsl:comment><xsl:value-of select="$order"/></xsl:comment>
        <xsl:for-each select="key('item',@row)">
                <xsl:sort select="@col" order="{$order}" data-type="number"/>
                <xsl:copy-of select="."/>
        </xsl:for-each>
</xsl:for-each>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«There are only 10 types of people in this world. Those who understand binary, and 
those who don't»

--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>
  • Re: Alternate sort order of subelements based on previous parent element, Joris Gillis <=