[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
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() < 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() < 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|