Re: [xsl] select immediately following siblings with constraints?

Subject: Re: [xsl] select immediately following siblings with constraints?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 23 Feb 2006 18:13:13 -0500

At 01:54 PM 2/23/2006, you wrote:
Thank you very much for the reply.  I actually hadn't been aware of
the << and >> operators, I shall have to read up on them.

Yes, they're fun, and ought to be useful for all kinds of neat things we haven't discovered yet.

  I did think
about using a for loop, I just wasn't sure how I could write one which
would be efficent, which wouldn't end up taking a lot more time than
necessary to run down the remaining following-sibling elements.

Note my attempt with the "for" expression (which actually isn't a loop but a mapping operation over a sequence, here applied to fake a "let" rather than perform a mapping :-) won't catch following sibling a elements when there is no following sibling b, so you'd have to add such following sibling a elements explicitly, for completeness.


((for $b in following-sibling::b[1]
    return following-sibling::a[. &lt;&lt; $b]),

... which is even less orthodox than ever.

Without the current() function you have to do

((for $b in following-sibling::b[1]
    return following-sibling::a[. &lt;&lt; $b]),
 (for $s in .
    return following-sibling::a[not($s/following-sibling::b)]))

I just tried this; amazingly enough it seems to work.

It remains a good question how much of this work should be done in XPath. I think the XSLT side is often easier to work with even if it's more verbose.

As for efficiency, being blissfully ignorant of most of what happens under the covers, I generally don't worry too much about that; but I doubt this would be a problem in most documents. (It might be in one that was unusually long and flat.) My general attitude is that performance is never a problem until it actually is one.

Which of the XPath or XSLT approaches would create more of an impression of wizardry, I leave for you to consider. :->


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML

Current Thread