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

Re: I need to sort and then display only the first 12

Subject: Re: I need to sort and then display only the first 12 entries of a node set
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Feb 2003 09:56:33 +0000
first only
Hi Bill,

> I did a foreach, and sorted inside that and did an if (position)
> type thing...

Glad you found the solution! :)

> I am not sure why this worked... Why the position reflects
> differntly inside the foreach... But it works so what the heck :)

The position() function always gives you the position of the context
node (the node you're looking at) within the context node list (the
nodes you're processing in whatever order you're processing them).

In a predicate as in location path like:

  /Shsmith/Newsletters/Newsletter[position() &lt; 12]

the context node is the node that you're testing (a <Newsletter>
element in this case) and the context node list contains the nodes
that you've selected with the step (all the <Newsletter> elements in
this case). In a location path step, the nodes in the context node
list are arranged in an order dependant on the axis that you use:
here, using the child axis, it's in document order (the order in which
they appear in the document).

Within an <xsl:for-each> as in:

  <xsl:for-each select="/Shsmith/Newsletters/Newsletter">
    <xsl:sort select="@dateposted" order="descending" />
    <xsl:if test="position() &lt; 12">
      ...
    </xsl:if>
  </xsl:for-each>

The context node and nodes in the context node list are again the
<Newsletter> elements, but this time the order of the context node
list is the sorted order based on the @dateposted attribute.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.