[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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()<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
|
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
|