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


"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


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