[xsl] an error I do not understand

Subject: [xsl] an error I do not understand
From: Graydon <graydon@xxxxxxxxx>
Date: Thu, 29 Sep 2011 20:07:27 -0400
So I've got a recurrent issue with taking big (~.5 Mlines, ~15 MiB)
files of metadata and merging them, or updating them.

(this happens in an XSLT 2.0 environment.)

Below is the minimal case of the error I do not understand:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xs xd" version="2.0"
  xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl";
  xmlns:xs="http://www.w3.org/2001/XMLSchema";
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:variable name="areaNames" select="distinct-values(/wkna-shared-cms/area/@area)"/>
  <xsl:key match="area" name="name2Area" use="@area"/>
  <xsl:template match="/">
    <xsl:for-each select="$areaNames">
      <!-- F [Saxon-PE 9.3.0.5] Leading '/' cannot select the root node of the tree containing the context item: the context item is an atomic value -->
      <xsl:sequence select="key('name2Area',current())"/>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

I get that the context node inside the for-each is an atomic value,
because once I use distinct-values() on the list of attribute values
that's what I get, but I don't understand why the key function can't
accept a string atomic value.

I've got the whole thing working using xsl:for-each-group, rather than
iterating directly through the area attribute values, but I'm right
stumped about why the above isn't acceptable to the parser, and am
hoping someone can explain it to me.

Thanks!
Graydon

Current Thread