[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
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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|