[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|