Re: [xsl] More Efficient way of mathching ID's

Subject: Re: [xsl] More Efficient way of mathching ID's
From: "Alexander Johannesen" <alexander.johannesen@xxxxxxxxx>
Date: Tue, 4 Apr 2006 06:43:47 +1000
Hi,

On 4/4/06, Spencer Tickner <spencertickner@xxxxxxxxx> wrote:
> *** Without.xml ***
> <?xml version="1.0"?>
> <document>
>         <article qpid="004243">
>                 <title>Test test Test Test Test</title>
>                 <sentence qpid="007309">
>                         <text>
>                                 Test test Test Test Test</text>
>                 </sentence>
>         </article>
...

In your XSLT you've got a *very* expensive lookup
"$fIntents//sentence" which you create every time you hit that
template. You could move this part of your selection into the global
scope, which probably also would speed up the existing code quite a
bit (depending on processor).

   <xsl:variable name="qpid" select="$fIntents//sentence[@qpid]" />

and use this locally ;

   <xsl:apply-templates select="$qpid[@qpid = $mykey]/intentref"/>

> As a note, reference.xml is much much bigger than this small test and
> will have all the qpid's I need to deal with the qpid's in without.xml
> file,, as well as a bunch more that will not be needed. I hope this
> illustrates what I' trying to do.

Sure. One question, though; is the schema for the without.xml file
set? Very often you'll find that if you've got id's and references
you'd get free boost through xsd:ID, so if you've got ;

   <article id="004243"> ... <sentence id="34563"> ...

you can use the XSLT function id() to quickly locate these, through
"<xsl:value-of select="id(@qpid)" />". This is also the only way to
create a key-set with multiple matches (if my memory servers), but
that might be minor. [http://www.dpawson.co.uk/xsl/sect2/N4598.html]

Also, your other speedy option is to use keys
[http://www.dpawson.co.uk/xsl/sect2/N4852.html] ; define a key in the
global scope and use it for your lookups;

   <xsl:key name="lut" match="@qpid" use="." />

Once you use this key on a set of data, a table is set up which will
be used for any next lookup as well, and some procesors might even
preempt their use and optomize further.


Alex
--
"Ultimately, all things are known because you want to believe you know."
                                                         - Frank Herbert
__ http://shelter.nu/ __________________________________________________

Current Thread