[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: Michael Kay <mike@xxxxxxxxxxxx>
Date: Sat, 22 Mar 2014 15:18:21 +0000
Re:  Best Way to Select Following Elements With An  Anc
> well if you know there's a dita acestor,
>
> count(ancestor::dita | $myDitaAncestor) = 1
>
> can be written
>
> ancestor::dita is $myDitaAncestor
>


I think you'll be very lucky if you find a processor that optimizes

following::*[ancestor::dita is $myDitaAncestor]

to only search the subtree of $myDitaAncestor. If this subtree is a small part
of the whole, then the expression is going to be pretty inefficient.

In general I suspect

$myDitaAncestor//*[. >> current()]

is likely to be better (it's not exactly equivalent of course because it will
also select ancestors of current()).

Probably the most efficient is to search following nodes until you reach one
that does not have the right ancestor, and then stop. This would be

<xsl:function name="following-in-subtree" as="element()*">
  <xsl:param name="this"/>
  <xsl:param name="ditaAncestor"/>
  <xsl:sequence select="
    if ($this/ancestor::* intersect $ditaAncestor)
    then ($this, following-in-subtree($this/following::*[1], $ditaAncestor))
    else ()"/>
</xsl:function>

(This relies on a conjecture about the following axis which I'm too lazy to
prove just now: that if A is on the following axis starting from B, then
A/following::* is a trailing subsequence of B/following::*)

Michael Kay
Saxonica

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.