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

RE: Sorting and position

Subject: RE: Sorting and position
From: Patrick Cauldwell <Patc@xxxxxxxxxxxx>
Date: Wed, 10 Nov 1999 11:23:56 -0800
position with sorting in xsl
You're right about the index confusion.  I've been using IE 5, which uses 0
based indexes.  I've just started using XT.  

I thought of using <xsl:if> as you suggest.  That works fine, but my concern
is that if I have 100+ possible elements and I only want 10, all 100+ are
still going to be avaluated the the <xsl:if>.  For a really large list I
would think that doing it in two passes would be more efficient.  True?

Patrick

-----Original Message-----
From: Kay Michael [mailto:Michael.Kay@xxxxxxx]
Sent: Wednesday, November 10, 1999 10:10 AM
To: 'xsl-list@xxxxxxxxxxxxxxxx'
Subject: RE: Sorting and position


>  I want to do is do something with the first two 
> <Product> elements, but I need to sort them by name first.
> 
> If I do this:
> 
> <xsl:template match="Products[position() >= 0 and position <= 1]">
> 	<xsl:for-each select="Product">
> 		<xsl:sort select="Name"/>
> 		<xsl:value-of select="Name"/>
> 	</xsl:for-each>
> </xsl:template>
> 
> I end up with the first two in document order, then sorted.  
> How can I come out with the first two in alpha order by Name?
>

Try:
 
 <xsl:template match="Products">
 	<xsl:for-each select="Product">
 		<xsl:sort select="Name"/>
            <xsl:if test="position()&lt;3">
 		    <xsl:value-of select="Name"/>
            </xsl:if>
 	</xsl:for-each>
 </xsl:template>

Note that position() starts at 1, your test on position()>=0 suggests some
confusion!

Actually there seems to be a terminology problem in the spec here. The spec
on sorting says that "the current node list consists of the complete list of
nodes being processed in sorted order", but the concept of "current node
list" has disappeared from XPath: position() is now defined to return the
"context position from the expression evaluation context".

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.