xsl-list
[Top] [All Lists]

Re: [xsl] Only child test

2013-10-10 09:55:39
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>