Re: [xsl] keys vs. parameters

Subject: Re: [xsl] keys vs. parameters
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 10 Jun 2002 08:47:29 +0100
Hi Peter,

>> You don't generate anything -- that's the responsibility of the
>> processor. Most implementations will "index" on an as-needed basis,
>> so if you don't refer to a key, there won't be any overhead. Since
>> the key() function can only return nodes in the same document as
>> the context node, a processor is required to keep information
>> separate for each source document. Again, with most
>> implementations, that means only the documents for which there is a
>> call of the key() function will be "indexed".
>> 
>> Both Xalan-J and Xalan-C++ implement keys this way.
>
> Ok, perhaps I'm missing something. I tried this with Xalan-J and in
> the context of a result set returned from an extension. I couldn't
> get the key to work. It was a pretty straight forward "match" and
> "using" (I've had far worse, including one I think I'm going to end
> up creating a question about come Monday) so I don't think I coded
> it wrong, but I'll try again...

>From a previous mail, I think you were trying:

> <xsl:key name="collection"
>   match="java:CollectionHandler.getCollection($collection_id, $group_id )"
>   use="local-name()"/>

Note that the match attribute should hold a *pattern* rather than a
*expression*. In other words, you don't select the nodes that you want
to be indexed in the key, you let the XSLT processor go through the
document(s) and create entries for those nodes in the document that
match the pattern. For example, if you did:

<xsl:key name="params" match="req:param" use="@name" />

then the key would match all the req:param elements in the document,
wherever they occur, and index them by their name attribute.

The other problem is that, to avoid circularity where a variable is
defined as the result of a call to a key, which is itself defined
based on that variable, you're not allowed to include variable
references within either the match attribute or use attribute of
xsl:key. This is a static restriction (one that's assessed at compile
time rather than run time) that is, I think, dropped in XSLT 2.0.

Even if you fixed the variable reference problem, I doubt that Xalan
recognises your call to an extension function as a valid pattern,
although it might match those nodes that would have been selected with
the expression, I suppose.

I think that you were using the extension function in order to access
nodes in another of your source documents. Now David's explained to
you that you do that by changing the context node at the point at
which you *call* the key, perhaps you can readjust your key definition
so that it doesn't use the extension function. Or describe what you're
trying to do in a bit more detail so we can help you work out how to
do it.

By the way, I noticed in one of your previous mails you'd written:

 <xsl:variable name="inreq">
   <xsl:copy-of select="req:request/req:params/*"/>
 </xsl:variable>

This creates a result tree fragment -- a root node with copies of the
children of req:params as children. To go on to process that result
tree fragment, you'd have to convert the result tree fragment to a
node set, which takes time. Instead, just set the variable to the
original node set through the select attribute, with:

 <xsl:variable name="inreq" select="req:request/req:params/*"/>

and that way the processor doesn't have to create any new nodes or do
the conversion to a node set.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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


Current Thread