xsl-list
[Top] [All Lists]

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

2014-03-22 15:30:23
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(_at_)contrext(_dot_)com> 
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.

--~------------------------------------------------------------------
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>
--~--