Re: Loading an external file of index

Subject: Re: Loading an external file of index
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Fri, 23 Jun 2000 13:45:13 +0100

I must say that I haven't fully got my head around how document() and key()
interact, but I'll give it my best shot.

>What does means this "for-each" as soon as I use it only to load a 
>document ?

In my head, I translate 'for-each' as 'with'.  One of the side-effects of
for-each is that it sets the current node to something that you specify, so
if you use a select expression that only contains one node, it's just like
temporarily setting the current node to that node.

>Why not only ask to load the document using an "apply-template" for 
>loading ?

Selecting a document for applying templates to is just like starting with a
new input document.  When you start processing that document, any keys that
you've defined apply to that document rather than the input document.  So,
you could alternatively do something like:

   <xsl:key name="mysetofkeys" match="/keybase/key" use="@name" />

   <!-- match on the keyref in your input document -->
   <xsl:template match="keyref">
     <!-- apply templates to the keybase of your shared document
          with a parameter giving the name of the keyref         -->
     <xsl:apply-templates select="document('../shared/shared.xml')/keybase">
       <xsl:with-param name="keyrefname" select="@name" />

   <!-- match on the keybase of your shared document -->
   <xsl:template match="keybase">
     <xsl:param name="keyrefname" />
     <!-- because we're within the shared document, the key()
          indexes on matching nodes within that document,
          rather than the input document.                     -->
     <b><xsl:value-of select="key('mysetofkeys', $keyrefname)/ACRONYM" /></b>

I haven't tested this thoroughly, so it might need some fine tuning, but
I've tested the basic principal and it seems to apply.

>Does this "for-each" means that a processor needs to load and 
>reparse all keys declarations each time ?
>Also, I'm a little bit curious on performances : for now the document 
>database is not so heavy. But let suppose, later having a 10 000 document 
>database with something like 100 keyref in each document.
>Would an XSL transformer need to load the shared file 100 times per 
>document ? Even, looking at the syntax, would it need to load it, for each 
>keyref element, as many times as needed before finding the right key in the 
>shared document ?

I'm really not sure.  I imagine that the processor would make some
optimisations, but you'd have to ask someone who'd written one.

I'm sorry I can't be more help,


Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email

 XSL-List info and archive:

Current Thread