Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Benefits of using xsl:key

From: "Michael Kay" <mike@--------.--->
To: <xsl-list@-----.------------.--->
Date: 11/3/2009 9:31:00 AM
> 
> We often hear that the use of xsl:key can speed up a 
> transformation many times. But XSLT processors seem so 
> optimized for speed, anyway, these days, that I have found it 
> difficult to construct a test input file and a test XSLT 
> stylesheet demonstrating the dramatic wonders of using xsl:key.
> 
> How big should the input document be?
> How complicated the hierarchy, etc?
> 

Try this query, which is Q8 from the XQuery XMark benchmark translated into
XSLT.

<result xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="2.0">
<!-- Q8.  List the names of persons and the number of items they bought.
          (joins person, closed_auction) -->

  <xsl:for-each select="/site/people/person">
    <xsl:variable name="a" 
       select="/site/closed_auctions/closed_auction[buyer/@person =
current()/@id]"/>
    <item person="{name}"><xsl:value-of select="count($a)"/></item>  
  </xsl:for-each>
  
</result>  

Run it against different sizes of database from the XMark benchmark. Observe
how with Saxon-HE the performance increases quadradically with database
size, while with Saxon-EE the increase is linear. That's because Saxon-EE
creates a key automatically. Then show how you can achieve the same effect
with Saxon-HE by hand-optimizing using xsl:key: introduce

<xsl:key name="k" match="/site/closed_auctions/closed_auction"
use="buyer/@person"/>

and change the variable initializer to

select="key('k', @id)"

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

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 www.altova.com/list/index.html. 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.

.
.

transparent

transparent