[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: Standard problem?


Subject: RE: Standard problem?
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Tue, 10 Oct 2000 10:10:26 +0100

> Well, hmm, looked great but I have a minor problem. Plugging
> this code into my real application (the nodes contain
> much more data) this maneuver boosts my processing times
> from 5 seconds processing time for a little web site to 160
> (using SAXON). Are there any known principles for performance
> optimizing XSL?

The best principle I can think of is "assume that the XSLT processor is not
going to do anything clever." Your code asks the processor, for each node in
the tree, to see whether than node has a parent with a descendant with the
attribute @id. That's clearly an n-squared algorithm, so if the tree gets 10
times bigger it will take 100 times as long.

Very often the answer to avoiding n-squared algorithms is to use keys. For
example, here you could declare a key something like:

<xsl:key name="id-uncles" match="@id" use="ancestor::* | ancestor::*/*"/>

and then replace the <xsl:if test="../descendant-or-self::*[@id=$thisid]">
by <xsl:if test="count(key('id', $thisid) | .) = count(key('id', $thisid))">

(this test determines whether the context node is in the node-set returned
by the key function)

> > -----Ursprüngliche Nachricht-----
> > Von: Nestel, Frank [mailto:frank.nestel@xxxxxx]
> > Gesendet am: Montag, 9. Oktober 2000 16:59
> > An: 'xsl-list@xxxxxxxxxxxxxxxx'
> > Betreff: AW: Standard problem?
> > 
> > Thank you, great, this much more beautiful than my stuff
> > and works nicely. I knew there must have been s.th. easier.
> > 
> > > -----Ursprüngliche Nachricht-----
> > > Von: David Carlisle [mailto:davidc@xxxxxxxxx]
> > > Gesendet am: Montag, 9. Oktober 2000 16:34
> > > An: xsl-list@xxxxxxxxxxxxxxxx
> > > Betreff: Re: Standard problem?
> > > 
> > > 
> > > 
> > > > This is, to every node I'd like to have
> > > > all its parents and their siblings, I'd also like to
> > > > have the node and it's siblings and the direct 
> > > > childs of the node. 
> > > 
> > > Isn't that just "I'd like to have all direct children of 
> > any ancestor.
> > > 
> > > I think you want something like
> > > 
> > > 
> > > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> > >                 version="1.0"
> > >                 >
> > > 
> > > <xsl:strip-space elements="*"/>
> > > 
> > > <xsl:output method="xml" indent="yes"/>
> > > 
> > > <xsl:param name="thisid" select="'A1'"/>
> > > 
> > > <xsl:template match="*">
> > >  <xsl:if test="../descendant-or-self::*[@id=$thisid]">
> > >  <xsl:copy>
> > >   <xsl:copy-of select="@id"/>
> > >   <xsl:apply-templates/>
> > >  </xsl:copy>
> > >  </xsl:if>
> > > </xsl:template>
> > > 
> > > </xsl:stylesheet>
> > > 
> > > 
> > > 
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <x>
> > > <NODE id="A">
> > > <NODE id="A1"/>
> > > <NODE id="A2"/>
> > > <NODE id="A3">
> > > <NODE id="A3i"/>
> > > <NODE id="A3ii"/>
> > > </NODE>
> > > </NODE>
> > > <NODE id="B"/>
> > > <NODE id="C"/>
> > > </x>
> > > 
> > > 
> > > David
> > > 
> > > 
> > > 
> > >  XSL-List info and archive:  
> > http://www.mulberrytech.com/xsl/xsl-list
> > > 
> > 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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



Current Thread
Keywords