[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: select immediately following siblings with constr

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

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.


Thus:

((for $b in following-sibling::b[1]
    return following-sibling::a[. &lt;&lt; $b]),
 (following-sibling::a[not(current()/following-sibling::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. :->

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
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

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.