[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Benefits of using xsl:key
I think I got MK's idea wrong in the stylesheet I presented in my last mail, but it is now corrected at the end of this mail, and it works as I said. To wrap it all up, I have made two datasets, one with only two distinct values of 3000 and the other with 2992 distinct values of 3000. These two datasets are only about duplicate values. The test is only an indication of how xsl:key can be useful with this type of dataset. Since optimization in Saxon EE isn't useful for duplicates, I have only made this test with Saxon HE (Home Edition), formerly known as Saxon B for "basics". far-from-distinct-values.xml 2 distinct out of 3000 1) no key: 13.1s 2) using key: 0.1 3) also key in match: 5.4s almost-distinct-values.xml 2992 distinct out of 3000 4) no key: 3.6s 5) using key: 3.6 6) also key in match: 0.1s MK has explained why 2 works better than 3 and why 6 works better than 5. The above is of cause only one type of dataset, but it shows to me that xsl:key can make a big difference and that fine tuning a template's match attribute can make a big difference. But it must all be done carefully, and it is necessary to analyze the dataset to find the best approach, and to test different approaches in order to find the best one (fast). Here is the corrected example of using xsl:key in the match attribute: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:key name="item-content" match="item" use="."/> <xsl:template match="item[. is key('item-content', current())[1]]"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="item"> <xsl:copy> <!-- add attribute and skip content --> <xsl:attribute name="refid" select="key('item-content', .)[1]/@id"/> <xsl:apply-templates select="@*"/> </xsl:copy> </xsl:template> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> cheers, Jesper
|
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
|