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

Re: Best Way to Select Following Elements With An Anc

Subject: Re: Best Way to Select Following Elements With An Ancestor?
From: David Rudel <fwqhgads@xxxxxxxxx>
Date: Sat, 22 Mar 2014 21:30:06 +0100
Re:  Best Way to Select Following Elements With An  Anc
If you really only need to know whether the nodes exist, and you are
going to be doing this check multiple times, I would think the most
efficient option would be to just find all the nodes that fail the
criterion in a single pass.

You can build up this node set in the following way: for each child of
the root, take the last child, take the last child of that node, take
the last child of that node... and put all those nodes in a sequence
(throwing in the children of the root element as well).

This can be done recursively by creating a function $f such that
$f($x) = (($x/element())[last()] , $f($x/element()[last()]))

Then create a sequence of nodes:
<xsl:variable name="youngest" as="node()*">
<xsl:for-each select="/element()">
<xsl:sequence select="$f(.)"/>
</xsl:for-each>
</xsl:variable>

In one pass this will generate the set of all element nodes for which
no following node exists in the context. You can then just test
whether the node you are looking at is in the group (testing by
identity rather than value).

Unlike the previous recursive method, this will not tell you anything
about what the following node is... just that there is one.

-David


On Sat, Mar 22, 2014 at 7:00 PM, Eliot Kimber <ekimber@xxxxxxxxxxxx> wrote:
> For my specific problem I only need to know if the nodes exist.


-- 

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.

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.