[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: A question on optimization

Subject: Re: A question on optimization
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 2 Nov 2004 15:08:01 GMT
for loop in xsl
> You are most probably right. I'd possibly better quote my actual loop:

  <xsl:for-each select="//justus:choice">
     <xsl:element name="TR">
       <xsl:variable name="current" select="."/>
       <xsl:for-each select="//justus:part[@visible='true']">

oops two occurrences of // 
// means 
  "please take ages traversing my entire document tree to its full
  depth looking for nodes of this form".
You are doing that inside a loop so this is massively expensive.

    <xsl:for-each select="//justus:choice">
      <xsl:element name="tr">
        <xsl:element name="td"><xsl:value-of select="a1"/></xsl:element>
        <xsl:element name="td"><xsl:value-of select="a2"/></xsl:element>

even that is expensive if your justus:choice elements have any element
content, you may know that there are no nested elements of that name and
none inside yourjustus:part elements but the system doesn't. If they are
all at the same level of the tree it's much better to say

  <xsl:for-each select="/a/b/c/justus:choice">

for whatever values of a b c you need.

back to your original loop. you have

 <xsl:for-each select="//justus:part[@visible='true']">

which is a) expensive and (b) inside your justus:choice loop and (c)
doesn't depend on the current node so will give the same result each
time. so you  could move this outside the loop:

<xsl:variable name="x" select="/a/b/justus:part[@visible='true']">

and then use

  <xsl:for-each select="$x">

which might be quicker, or it might be just the same, if your xslt
system noticed that that was a constant expression and so optimised it
out of the outer loop automatically.

I don't really have a picture of your input format in my head so
probably this won't work out of the box, but you probably want to use a
key (whicj basically tells the processor to make some kind of hash table
which can dramitacally improve access times rather than seraching an
entire document repeatedly) it seems like the things you need to get to
fast are justus:part so
<xsl:key name="j" match="justus:part" use="@visisble"/>
   <xsl:for-each select="/a/b/justus:choice">
  <xsl:variable name="current" select="."/>
 <xsl:variable name="current" select="."/>
 <xsl:for-each select="key('j','true')">
   <xsl:variable name="dbfeld" select="."/>
   <xsl:value-of select="$current/@*[name()=$dbfeld/@dbfeld]">

This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.