[xslt] long processing time when using key that returns an empty node set



Hi,

When I have a xsl:key who’s select results in no nodes, I notice a ridiculous increase in processing time.

Below is an example that runs in 4ms when the select returns nodes and 2400ms when no nodes are in the key.

If you run it with more nodes in the xml you’ll get even slower performance.

Thanks,

tim

 

 

Xml

<?xml version="1.0" encoding="utf-8"?>

 

<document>

<node id='1'/>

<node id='2'/>

<node id='3'/>

<node id='4'/>

<node id='5'/>

..etc etc

<node id=’2000’/>

</document>

 

 

Xsl

 

<xsl:stylesheet version='1.0'

        xmlns:xsl='http://www.w3.org/1999/XSL/Transform'

> 

    <xsl:output method='text' version='1.0' encoding='utf-8' indent='no'/>

<!--

        <xsl:key name="idKey" match="/document/node[ id='-1']" use="@id" />

-->

        <xsl:key name="idKey" match="/document/node[ id='2000']" use="@id" />

 

 

        <xsl:template match="/">

                <xsl:value-of select="count(

                                                key('idKey', /document/node/@id)

                                        )"

                />

        </xsl:template>

</xsl:stylesheet>

 

 

 

With

<xsl:key name="idKey" match="/document/node[ id='-1']" use="@id" />

 

[tomcat hulk xsltests]$ xsltproc -timing -profile test.xsl test.xml.small

Parsing stylesheet test.xsl took 0 ms

Parsing document test.xml.small took 2 ms

number               match                name      mode  Calls Tot 100us Avg

 

    0                    /                                    1 244198 244198

 

                         Total                                1 244198

Applying stylesheet took 2443 ms

0Saving result took 0 ms

 

 

With

            <xsl:key name="idKey" match="/document/node[ id='2000']" use="@id" />

 

[tomcat hulk xsltests]$ xsltproc -timing -profile test.xsl test.xml.small

Parsing stylesheet test.xsl took 0 ms

Parsing document test.xml.small took 2 ms

number               match                name      mode  Calls Tot 100us Avg

 

    0                    /                                    1    346    346

 

                         Total                                1    346

Applying stylesheet took 4 ms

1Saving result took 0 ms

 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]