Re: [xsl] Trouble using xsl:key under XSL 1.0

Subject: Re: [xsl] Trouble using xsl:key under XSL 1.0
From: Abel Braaksma <>
Date: Thu, 13 Dec 2007 18:13:28 +0100
Scott Trenda wrote:
<xsl:key name="playerResultLookupByWeek" match="playerResult[../@week=$week]" use="@player" />

A big thing to watch out for here - the xsl:key match must be a pattern,
which is required to be context-free. (Same as the match pattern in
xsl:template.) And one of the big limitations to patterns is that you
cannot have variable references inside them. Even if the variable is
top-level, and even if it's something simple like
document('')/*/someElement, it can't be used in the match pattern.

Learn to start thinking around variables in your keys, and you'll end up
banging your head against the wall less often. :)

Unless you start out with XSLT 2.0 of course, which does allow (global) variables in patterns. So leave that wall near by in case you want to switch to 2.0 anytime soon ;)

-- Abel Braaksma

Current Thread