Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Benefits of using xsl:key

From: Jesper Tverskov <jesper.tverskov@-----.--->
To: xsl-list@-----.------------.---
Date: 11/5/2009 9:35:00 AM
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

--~------------------------------------------------------------------
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