Re: [xsl] Lookup efficiency in XALAN?

Subject: Re: [xsl] Lookup efficiency in XALAN?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 20 Nov 2003 18:05:17 -0500
J,

At 04:45 PM 11/20/2003, you wrote:
I have to do some validation in my xsl.

I'm doing the following type statement 20,000 times, and the lookup file is
around 50,000  lines of  id's <id key="XXYYZZJ"/>.

<xsl:when test="not(document('../master/ids-master.xml')/ids/id[@key=$id])">

It works for a while, then dies with an out of memory error, and it sure is
slow!

The first thing you should definitely do is collect the lookup ids into a variable, as in


<xsl:variable name="keys" select="document('../master/ids-master.xml')/ids/id/@key"/>

Then you can test your local ids against the keys in the variable, without parsing your lookup file every time (which it sounds like your processor might be doing):

<xsl:when test="not($id = $keys])">

Try that and see if it helps.

If Xalan is already optimizing the document() lookup and parse, you may get no gain from this technique -- but there's no way it could hurt.

XSLT keys could also help, but since your keys are in a separate document you'd have to switch contexts to use the XSLT key function, like so:

<xsl:key name="keys-by-id" match="id" use="@key"/>

<xsl:variable name="keyfile" select="document('../master/ids-master.xml')"/>

... and then

<xsl:for-each select="$keyfile">
  <xsl:when test="not(key('keys-by-id', $id))">...</xsl:when>
</xsl:for-each>

but whether this helps also will depend on your processor and what kind of smarts it has inside.

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread