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

RE: First Element in Sorted List

Subject: RE: First Element in Sorted List
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Wed, 1 Jun 2005 15:16:23 +0100
sortedlist first element
> I am hoping to to confirm something before going in the wrong
> direction.
>
> My process needs to take action on the first element in a list of
> elements where the logic to determine first is the lowest
> numeric value
> of the sortorder attribute.  I don't believe there is a
> one-line way to
> do this - I believe the entire list must be sorted, and then the
> position of each element after sort compared to determine if
> it is first.
>
> Is there a shorter/less expensive way to code the following
>
> <xsl:for-each select="item">
>    <xsl:sort select="@sortorder" data-type="number" />
>    <xsl:if test="position() = 1">
>      <!-- this is the first element in the sorted list -->
>    </xsl:if>
> </xsl:for-each>
>
> I searched and found examples using this technique, but
> nothing really
> saying that this was the best or only approach.

Yes, in 1.0 that's the best way.  You could use an extension function if
portability isn't an issue, such as exslt's math:min().

2.0 has the min() function inbuilt (if you are using Saxon you can
pick-and-choose(TM) the features of 2.0 you want and use them in your
1.0 stylesheet).

cheers
andrew

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.