2004-12-13

XSLT

The key() function is sensitive to the current context node in that it will only find nodes that are in the current document.  This is surprising behaviour.  The XSLT specification actually notes this "feature" (read: bug) at the end of section 12.2.  It suggests using <xsl:for-each select="$document"> construct to switch the context prior to using the key function.  That wouldn't work for me in a stylesheet that I was working on because I needed an XPath expression.  This worked:  $root[key('...', ...)]