Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 24th, 2006, 03:43 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to daula7
Default xsl performance problem

Hello;
I'm trying to process an autogenerated xml file (has over 6000 lines) using the stylesheet listed below.
My problem is that when I ran xsltproc on a redhat box, using the two files, it takes forever to process and get worse with an even bigger xml.

Is there any recommendations on what I need to change on this xsl to improve the performance??

Thanks in advance

daula

--xsl code--
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dts="uri:dts_namespace">
<xsl:output method="text" version="1.0"/>

<xsl:param name="six_m" select="'00-06 '"/>
<xsl:param name="twelve_m" select="'07-12 '"/>
<xsl:param name="twenty4_m" select="'13-24 '"/>


<xsl:key name="skey" match="dts:tally[@dts:name='dc_range']" use="dts:value" />

<xsl:template match="/">
    <xsl:call-template name="list" />
    <xsl:call-template name="sum" />
</xsl:template>

<xsl:template name="list">
    <xsl:for-each select = "dts:dtservices/dts:tally_output/dts:tally/dts:tally">
        <xsl:value-of select = "dts:value" />
        <xsl:text>,</xsl:text>
        <xsl:variable name = "cnt1" select = "dts:tally[1]/dts:count" />
        <xsl:variable name = "cnt2" select = "dts:tally[2]/dts:count" />
        <xsl:variable name = "cnt3" select = "dts:tally[3]/dts:count" />
        <xsl:variable name = "tot1" select = "$cnt1" />
        <xsl:variable name = "tot2" select = "$cnt1 + $cnt2" />
        <xsl:variable name = "tot3" select = "$cnt1 + $cnt2 + $cnt3" />

        <xsl:variable name = "net1">
            <xsl:call-template name="foreach">
                <xsl:with-param name="item" select="$six_m"/>
            </xsl:call-template>
        </xsl:variable>

        <xsl:variable name = "net2">
            <xsl:call-template name="foreach">
                <xsl:with-param name="item" select="$twelve_m"/>
            </xsl:call-template>
        </xsl:variable>

        <xsl:variable name = "net3">
            <xsl:call-template name="foreach">
                <xsl:with-param name="item" select="$twenty4_m"/>
            </xsl:call-template>
        </xsl:variable>

        <xsl:variable name = "real_net2" select = "$net1 + $net2" />
        <xsl:variable name = "real_net3" select = "$net1 + $net2 + $net3" />

        <xsl:variable name = "zero" select = "0" />
        <xsl:choose>
           <xsl:when test="$tot1 = NaN">
                <xsl:value-of select = "$zero" />
                <xsl:text>,</xsl:text>
                <xsl:value-of select="format-number((($zero div $net1)*100), '##.##')" />
                <xsl:text>%,</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select = "$tot1" />
                <xsl:text>,</xsl:text>
                <xsl:value-of select="format-number((($tot1 div $net1)*100), '##.##')" />
                <xsl:text>%,</xsl:text>
            </xsl:otherwise>
            <xsl:when test="$tot2 = NaN">
                <xsl:value-of select = "$zero" />
                <xsl:text>,</xsl:text>
                <xsl:value-of select="format-number((($zero div $real_net2)*100), '##.##')" />
                <xsl:text>%,</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select = "$tot2" />
                <xsl:text>,</xsl:text>
                <xsl:value-of select="format-number((($tot2 div $real_net2)*100), '##.##')" />
                <xsl:text>%,</xsl:text>
            </xsl:otherwise>
            <xsl:when test="$tot2 = NaN">
                <xsl:value-of select = "$zero" />
                <xsl:text>,</xsl:text>
                <xsl:value-of select="format-number((($zero div $real_net3)*100), '##.##')" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select = "$tot3" />
                <xsl:text>,</xsl:text>
                <xsl:value-of select="format-number((($tot3 div $real_net3)*100), '##.##')" />
            </xsl:otherwise>
        </xsl:choose>

        <xsl:text>%#xa;</xsl:text>
    </xsl:for-each>
</xsl:template>

<xsl:template name="sum">
    <xsl:text>#xa;</xsl:text>
    <xsl:text>Total: </xsl:text>

    <xsl:variable name = "sum1">
        <xsl:call-template name="foreach">
            <xsl:with-param name="item" select="$six_m"/>
        </xsl:call-template>
    </xsl:variable>

    <xsl:variable name = "sum2">
        <xsl:call-template name="foreach">
            <xsl:with-param name="item" select="$twelve_m"/>
        </xsl:call-template>
    </xsl:variable>

    <xsl:variable name = "sum3">
        <xsl:call-template name="foreach">
            <xsl:with-param name="item" select="$twenty4_m"/>
        </xsl:call-template>
    </xsl:variable>

    <xsl:value-of select = "$sum1"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select = "$sum1 + $sum2"/>
    <xsl:text>,</xsl:text>
    <xsl:value-of select = "$sum1 + $sum2 + $sum3"/>
    <xsl:text>#xa;</xsl:text>
</xsl:template>

<xsl:template name="foreach">
    <xsl:param name="item"/>
    <xsl:for-each select="//dts:tally[@dts:name='dc_range' and dts:value=$item][count(. | key('skey', dts:value)[1]) = 1]">
        <xsl:value-of select = "sum(//dts:tally[@dts:name='dc_range' and dts:value=$item]/dts:count)" />
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

--xsl code--


-- xml snip--
<dts:dtservices xmlns:dts="uri:dts_namespace">
    <dts:tally_output>
        <dts:tally dts:name="test_lrfs">
            <dts:tally dts:name="cState">
                <dts:tally dts:name="dc_range">
                    <dts:value>00-06 </dts:value>
                    <dts:count>26</dts:count>
                </dts:tally>
                <dts:tally dts:name="dc_range">
                    <dts:value>07-12 </dts:value>
                    <dts:count>26</dts:count>
                </dts:tally>
                <dts:tally dts:name="dc_range">
                    <dts:value>13-24 </dts:value>
                    <dts:count>34</dts:count>
                </dts:tally>
                <dts:value>AK</dts:value>
                <dts:count>86</dts:count>
            </dts:tally>
            <dts:tally dts:name="cState">
                <dts:tally dts:name="dc_range">
                    <dts:value>00-06 </dts:value>
                    <dts:count>100</dts:count>
                </dts:tally>
                <dts:tally dts:name="dc_range">
                    <dts:value>07-12 </dts:value>
                    <dts:count>74</dts:count>
                </dts:tally>
                <dts:tally dts:name="dc_range">
                    <dts:value>13-24 </dts:value>
                    <dts:count>121</dts:count>
                </dts:tally>
                <dts:value>AL</dts:value>
                <dts:count>295</dts:count>
            </dts:tally>
            <dts:tally dts:name="cState">
                <dts:tally dts:name="dc_range">
                    <dts:value>00-06 </dts:value>
                    <dts:count>72</dts:count>
                </dts:tally>
                <dts:tally dts:name="dc_range">
                    <dts:value>07-12 </dts:value>
                    <dts:count>57</dts:count>
                </dts:tally>
                <dts:tally dts:name="dc_range">
                    <dts:value>13-24 </dts:value>
                    <dts:count>68</dts:count>
                </dts:tally>
                <dts:value>AR</dts:value>
                <dts:count>197</dts:count>
            </dts:tally>
        </dts:tally>
    </dts:tally_output>
</dts:dtservices>
--xml snip--

  #2 (permalink)  
Old May 25th, 2006, 04:25 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This kind of logic:

<xsl:for-each select="//dts:tally[@dts:name='dc_range' and dts:value=$item]

can always be improved dramatically by using keys (xsl:key).

Alternatively, use an XSLT processor with an optimizer that does this for you automatically, such as Saxon-SA ;)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
performance issue with the xsl given here anboss XSLT 11 July 16th, 2008 03:05 AM
Performance for <xsl:import> and <xsl:include> vikkiefd XSLT 2 April 16th, 2008 08:06 AM
Performance (xsl:element and file size) jaybytez XSLT 1 June 6th, 2007 02:54 PM
Sql Server 2000 vs Oracle 9i - performance problem sniegu Hibernate 2 January 27th, 2006 12:10 PM
DTS Performance Problem abob SQL Server DTS 0 September 6th, 2005 04:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.