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

RE: Benefits of using xsl:key

Subject: RE: Benefits of using xsl:key
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 3 Nov 2009 09:30:19 -0000
RE:  Benefits of using xsl:key
> 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 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.