xsl-list
[Top] [All Lists]

Re: [xsl] following-sibling is evil

2014-07-06 10:48:22
On Sun, July 6, 2014 11:29 am, Michael Kay mike(_at_)saxonica(_dot_)com 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(_at_)mentea(_dot_)net
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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>