[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Best Way to Select Following Elements With An Ancestor?


Subject: Re: [xsl] Best Way to Select Following Elements With An Ancestor?
From: David Rudel <fwqhgads@xxxxxxxxx>
Date: Sat, 22 Mar 2014 21:30:06 +0100

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