This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: sort / unsort
- From: Mike Berrow <mberrow at pacbell dot net>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 08 Aug 2002 17:43:12 -0700
- Subject: Re: [xsl] sort / unsort
- References: <5BD25A6682008A4F96D74BF5AD2397ECC0F8B1@clttmp21.ncmi.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
That was fun!!
Here is how I did it ...
==============================
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="nodes">
<xsl:variable name="fooSet" select="foo"/>
<xsl:variable name="topSortedIDs">
<xsl:for-each select="$fooSet">
<xsl:sort select="."/>
<xsl:if test="position() < 6">
<xsl:value-of select="generate-id()" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
<partlySortedSet>
<xsl:for-each select="foo">
<xsl:sort select="."/>
<xsl:if test="position() < 6"><xsl:copy-of select="."/></xsl:if>
</xsl:for-each>
<xsl:text>
</xsl:text>
<xsl:comment>Unsorted Remainder</xsl:comment>
<xsl:for-each select="$fooSet">
<xsl:variable name="currNode" select="."/>
<xsl:if test="not(contains($topSortedIDs,generate-id()))">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</partlySortedSet>
</xsl:template>
</xsl:stylesheet>
==============================
Does anyone see a better way?
-- Mike Berrow
----- Original Message -----
From: "McKeever, Marty" <marty.mckeever@bankofamerica.com>
To: <xsl-list@lists.mulberrytech.com>
Sent: Thursday, August 08, 2002 12:44 PM
Subject: [xsl] sort / unsort
Interesting problem, i've been wracking my brain to solve.
>From a group of nodes, output the first five in a sorted order, and dump the
remainder in document order.
that is:
<foo>I</foo>
<foo>F</foo>
<foo>E</foo>
<foo>D</foo>
<foo>A</foo>
<foo>C</foo>
<foo>B</foo>
<foo>H</foo>
<foo>G</foo>
would output:
<foo>A</foo>
<foo>B</foo>
<foo>C</foo>
<foo>D</foo>
<foo>E</foo>
<foo>I</foo>
<foo>F</foo>
<foo>H</foo>
<foo>G</foo>
note that only the first 5 are sorted.
the remainder are in document order - less the 5 sorted items.
TIA,
Marty
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list