Re: [xsl] Fwd: xsl:key() and $variables.

Subject: Re: [xsl] Fwd: xsl:key() and $variables.
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 24 Jul 2006 11:34:34 -0400
At 10:20 PM 7/21/2006, Mike wrote:
I've never heard of xsl:key but the second illustration here:

http://www.cranesoftwrights.com/resources/xslkeys/index.htm

looks useful. It seems an xsl:key is like a variable containing
a list of elements that match the xpath expression. But the key()
function allows you to filter on that list further by providing a key
(overloaded term warning). So in the above illustration the xsl:key
statement builds a list of Employee elements and indicates that the SSN
child should be used when a key is supplied to the key() function. So
the key('people',@emp) call says, "fetch all elements in the 'people'
list using the SSN @emp.

Nice writeup.


 Presumably each Employee would have a unique
SSN and therefore the key() call will return one Element.

And if the SSN isn't unique -- or maybe your key value is the surname not the SSN -- you could get several Employees back, all with the same SSN, surname or what have you.


Hence the applicability of keys for de-duplicating and accordingly for grouping.

Note there's nothing you can do with a key that you can't do with brute-force XPath. But since the processor has the information up front to build an index, many expensive tree traversals are avoided and the application scaled much better.

Cheers,
Wendell

Current Thread