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

Re: following-sibling is evil

Subject: Re: following-sibling is evil
From: "Tony Graham tgraham@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 6 Jul 2014 15:48:10 -0000
Re:  following-sibling is evil
On Sun, July 6, 2014 11:29 am, Michael Kay mike@xxxxxxxxxxxx wrote:
> Any reasonably intelligent processor will do an "early exit" on such an
> expression, which means it will only scan the following-sibling axis until
> it finds the first node that matches the predicates.
>
> However, this kind of logic is still O(n^2), and the performance is
> especially bad if there are few or no duplicates.
>
> It's much better to use constructs such as key() or distinct-values() or
> xsl:for-each-group for this kind of processing, though it may be difficult
> to achieve that in Schematron.

FWIW you can use key() with the default XSLT binding of Schematron.  From
Appendix C of ISO Schematron:

   The XSLT key element may be used, in the XSLT namespace, before
   the pattern elements.

If you didn't want to use keys and you had a Schematron processor with a
XSLT 3.0 binding (e.g., if you revised the ISO Schematron XSLT 2.0
stylesheet to be and produce XSLT 3.0) then you should be able to write a
'early exit' anonymous function along the lines of fold-right() and use
that.  But, of course, it would be better if the processor recognised the
intent of the following-sibling and did the early exit for you as Mike
says.

With XPath 2.0, you may be able to do something with 'some ... in ...
satisfies ...', but you'd be back to hoping that the processor works out
what's in 'in ...' one item at a time if changing to using that is
actually going to save you time and/or memory.

Regards,


Tony Graham                                         tgraham@xxxxxxxxxx
Consultant                                       http://www.mentea.net
Chair, Print and Page Layout Community Group @ W3C    XML Guild member
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
Mentea       XML, XSL-FO and XSLT consulting, training and programming

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.