Re: xxRe: [xsl] efficient use of key element and function

Subject: Re: xxRe: [xsl] efficient use of key element and function
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 7 Sep 2005 12:07:18 +0100
> I was thinking the use attribute only comes into play _after_ a match
> was found and in some way can be viewed as a return value (per node)

no you have that backwards, the use attribute specifies the allowe
_arguments_ to the key function, the match attribute specifies teh
returned value.

key('x',...) (in xslt1) is a function from strings to node sets

key('x','"foo") returns a set of nodes with key "foo".

The way this is function is defined is that the set of nodes returned is
the set of nodes that match the match attribute, and have a use
attribute that evaluates to "foo".

> > If might be better to match on text() than on *
>For my test-case it should be the same.

They will only be the same if your input document only has one element
(and no comments).

If you have

<xsl:key match="*" use="."/>

Then the key for the top level element will be all the character data in
the document, concatenated. The system will then have to ake a hash
table entry using that large string as label.

key('x',string(/*)) would then return this element, but you would be a
lot more efficient just to use
/*
without using keys at all.

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread