This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: How to efficiently remove "a" nodes with no "b" descend ants


> If I say
>
> > <xsl:template match="a[not(.//b)]"/>
>
> then all the descendants of "a" are checked for "b" elements. Let's
> have a closer look at the input structure.

> This presupposes that the XSLT processor you are using does
> no optimisation, which may or may not be true.
>

Optimizers look for "quick wins", constructs that are used sufficiently
often to be worth treating specially, and I suspect this isn't one of them.

Generally, it's bad news to put a complex test like this into a match
pattern, because there is little alternative to testing each node selected
by <apply-templates> against this pattern; there is more scope to optimise a
node-set expression than a pattern.

You might find that a more efficient approach is

<xsl:variable name="ancestors-of-b" select="//b/ancestor::*"/>
<xsl:variable name="anc-of-b-count" select="count($ancestors-of-b)"
<xsl:template match="a">
<xsl:if test="count(.|ancestors-of-b) != $anc-of-b-count">
 ...

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]