This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: follow up re: key execution speed
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] follow up re: key execution speed
- From: tcn at melvaig dot co dot uk (Trevor Nash)
- Date: Fri, 10 Aug 2001 15:17:54 GMT
- Organization: Melvaig Software Engineering Limited
- References: <B8A87EA8277ED5118DD400D0B73E8180025CE1@mail.corp.poindextersystems.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Wild idea: include your zip lookup file in the stylesheet either by
external entity reference or xsl:include (in the latter case you have
to put a stylesheet element in the zip file). In both cases you will
have to invent a namespace for it.
This *may* be enough to convince Xalan that its the same document
every time rather than a new one, hence it will only rebuild the index
when you prepare the stylesheet. I believe Saxon can be made to
behave this way, but Xalan may be different.
If I were you I think I would write a simple Java class to read the
zip table and access it from an extension function. Its not
difficult, and the memory footprint will be less than a tenth of the
XSLT method.
Regards,
Trevor Nash
>I wrote in last week and received much good advice on using keys to perform
>lookups during XSL execution. I was advised, properly I am sure, that keys
>are damn fast and the best way to do nearly anything. However my problem is
>a little unusual, and is resulting in unsatisfactory performance.
>
>The trick is this: while I have been advised that keys are speed for any
>lookup that will be performed more than once in a transform, my situation is
>a little more complicated. I only do this lookup once per transform, but I
>perform this transform many times (thousands!) on different source
>documents. I was hoping to get the speed benefit of the key across these
>multiple transformations.
>
>My XSL templates make use of two data files, Zips.xml, which maps zip codes
>to dealer codes, and Dealers.xml, which contains information about each
>dealer. The idea is to use a key (ziptorc) over the (very large - 400K) Zips
>file (looks like <ZIP zip='10001' rc='2'/>) to perform the zip-to-dealer
>mapping, then to use another key over the dealer file (rctodealer) to
>perform a generic templating of the dealer informaiton. My templates are as
>follows:
>
><xsl:key name="ziptorc" match="ZIP" use="@zip"/>
><xsl:key name="rctodealer" match="DEALER" use="@rc"/>
><xsl:template name="TARGETBYZIP">
> <!-- target by ZIP -->
> <xsl:variable name="ZIP">
> <xsl:value-of select="ZIP/@val"/>
> </xsl:variable>
> <xsl:variable name="RC">
> <xsl:for-each select="document('Zips.xml')">
> <xsl:value-of select="key('ziptorc', $ZIP)/@rc"/>
> </xsl:for-each>
> </xsl:variable>
> <xsl:for-each select="document('Dealers.xml')">
> <xsl:apply-templates select="key('rctodealer', $RC)"/>
> </xsl:for-each>
></xsl:template>
>
><xsl:template match="DEALER">
> <!-- generic template for displaying dealer information here -->
></xsl:template>
>
>I am using Xalan, creating and persisting a Templates object. I am then
>creating a Transformer object to perform each transform. Performance is very
>slow; seems to me that it is reloading the data files and recreating the
>keys every time it performs the transform.
>
>Is there some set of changes, to the XSL or to the Java, that will enable me
>to get the blazing performance I require?
>
>Thanks very much for your help.
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
--
Traditional training & distance learning,
Consultancy by email
Melvaig Software Engineering Limited
voice: +44 (0) 1445 771 271
email: tcn@melvaig.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list