Altova Mailing List Archives

Re: [xsl] XPath perfomance in attributes or nodes?

From: "Jonathan Perret" <jonathan@------------>
Date: 3/6/2002 11:42:00 PM
I would like to ask the XSLT implementors on this list whether their
processors build keys lazily (i.e. on the first use of the key() function),
or does <xsl:key> have a cost even when the key is not used later ?
When is the cost of building the index offset by the performance gain ?

For example, suppose the input is 10000 elements like so :

<elt att="1">
<elt att="2">
<elt att="3">

and there is an external parameter that gives the stylesheet
an attribute value to look for. Which would be faster :

<xsl:key name="idx" match="elt" use="@att" />
<xsl:param name="param" />

<xsl:template ...>
    <xsl:apply-templates select="key('idx',$param)" />

Or : 

<xsl:param name="param" />

<xsl:template ...>
    <xsl:apply-templates select="/doc/elt[@att=$param]" />

Assuming the <xsl:apply-templates> above is executed
only once, it seems to me that the key-less version
should perform a bit faster. But as I have never implemented
an XSLT processor I would like to have the opinion of
masters of the subject.


----- Original Message ----- 
From: "Peter Davis" <pdavis152@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Thursday, March 07, 2002 3:52 AM
Subject: Re: [xsl] XPath perfomance in attributes or nodes?

> <xsl:key name="project-uid" match="project" use="@uid"/>
> <!-- or use="uid" -->
> <xsl:template ...>
>   <xsl:apply-templates select="key('project-uid',
>      '{6A97F258-93A7-4C5E-B712-052130A5208C}')[1]"/>
>   <!-- [1] is probably not necessary -->
> </xsl:template>
> will be much faster than either approach.

 XSL-List info and archive:


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.