This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How to efficiently remove "a" nodes with no "b" descend ants
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] How to efficiently remove "a" nodes with no "b" descend ants
- From: Teppo Peltonen <teppo dot peltonen at vtt dot fi>
- Date: 09 Mar 2001 19:19:47 +0200
- References: <001101c0a884$4dc54fe0$5d2a3c3e@oemcomputer>
- Reply-To: xsl-list at lists dot mulberrytech dot com
"Michael Kay" <mhkay@iclway.co.uk> writes:
> > This presupposes that the XSLT processor you are using does
> > no optimisation, which may or may not be true.
Yes, I agree. I really shouldn't make assumptions about the
implementation of the processor. However, when things get slow, I have
to come up with something....
> 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">
> ...
This looks really great! Create a set of all ancestors of all "b"
nodes and then check for each node "a" if it belongs to the set? I
wrote this like this:
<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">
<a>
<xsl:apply-templates/>
</a>
</xsl:if>
</xsl:template>
But, unfortunately I don't seem to be able to get it working right
now... For some reason Xalan always claims that
count(.|$ancestors-of-b) is 1. Hmm... have to look at it again
later. Can anybody spot any obvious typos or something?
> Mike Kay
Thank you very much,
Teppo
--
Teppo Peltonen <mailto:teppo.peltonen@vtt.fi> phone 09 4566080
VTT Information Technology mobile 040 5651878
Tekniikantie 4 B, P.O.Box 1201, Espoo 02044 VTT telefax 09 4567052
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list