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

Re: Only child test

Subject: Re: Only child test
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 10 Oct 2013 15:55:14 +0100
Re:  Only child test
On 10/10/2013 15:34, Andre Cusson wrote:
Wouldn't "last() eq 1" or "last() gt 1" be both the fastest and
clearest?

last() depends on the nodes that were selected, so it answers the question of whether 1 node was selected not if there are siblings.

given

<p><a/><b/><c/></p>

then b has two siblings but if you go

<xsl:apply-templates select="b"/>

last() will be 1 in the template matching b but if you go


<xsl:apply-templates />


Then it will be 3.


Like most of the constructs whether it is fast or not depends on the system optimiser. Naively evaluating last() eq 1 would require knowing what last() is so if there are 100000 items in the list you would have to hold back evaluating any of them until you had processed that one and knew the number but as with not(*[2]) an optimiser can evaluate the boolean expression last() eq 1" as soon as it has seen two items, even if it does not know what value last() has,

David

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.