title: XSLT 1.0 How to use xsl:key with document() function
body: <p>I'm trying to use xsl:key to lookup items in an external XML document, using the XSL document() function.  I am able to get the xsl:key part to work if, instead of using document(), I just merge the two XML files (using XmlDocument in C#).  However both XML files are very large, and I'm starting to get "out of memory" errors in some cases.  Also I need to be able to use xls:key, otherwise the process takes hours.</p>
  
  <p>In XSLT 2.0, I believe you can do something like this:</p>
  
  <pre class="lang-xsl prettyprint-override"><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
      &lt;xsl:variable name="lookupDoc" select="document('CodeDescriptions.xml')" /&gt;
      &lt;xsl:key name="LookupDescriptionByCode" match="Code/@description" use="../@code" /&gt;
  
      &lt;xsl:template match="ItemCode"&gt;
          &lt;xsl:call-template name="MakeSpanForCode"&gt;
              &lt;xsl:with-param name="code" select="text()" /&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template name="MakeSpanForCode"&gt;
          &lt;xsl:param name="code" /&gt;
          &lt;xsl:element name="span"&gt;
              &lt;xsl:attribute name="title"&gt;
                  &lt;xsl:value-of select="$lookupDoc/key('LookupDescriptionByCode', $code)" /&gt;
              &lt;/xsl:attribute&gt;
              &lt;xsl:value-of select="$code" /&gt;
          &lt;/xsl:element&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>How do you accomplish this in XSLT 1.0 though?</p>