xsl-list
[Top] [All Lists]

Re: select immediately following siblings with constraints?

2006-02-23 16:13:13
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(_at_)mulberrytech(_dot_)com
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
======================================================================


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