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