title: In XSLT 1.0 how to create a lookup function on XML data embedded in the XSLT using key and document('')?
body: <p>My specific need is to lookup line-heights given a particular font-size, but I am seeking to learn a general technique of creating lookups/a specific mapping.</p>
  
  <p>I think it is possible to embed XML in the XSLT document itself (so it can work standalone) and build a key on it using the document('') function to reference the current XSLT, something like this:</p>
  
  <pre><code>&lt;xsl:variable name="data.font-metrics.line-height"&gt;
      &lt;line-height font-size="11"&gt;12&lt;/line-height&gt;
      &lt;line-height font-size="12"&gt;14&lt;/line-height&gt;
      &lt;line-height font-size="13"&gt;15&lt;/line-height&gt;
      &lt;line-height font-size="14"&gt;16&lt;/line-height&gt;
      &lt;line-height font-size="15"&gt;17&lt;/line-height&gt;
      &lt;line-height font-size="16"&gt;18&lt;/line-height&gt;
      &lt;line-height font-size="17"&gt;20&lt;/line-height&gt;
      &lt;line-height font-size="18"&gt;21&lt;/line-height&gt;
  &lt;/xsl:variable&gt;
  &lt;xsl:key name="lookup.font-metrics.line-height" match="document('')//xsl:variable[@name='data.font-metrics.line-height'])/line-height" use="@font-size"/&gt;
  </code></pre>
  
  <p>After that, I should be able to lookup a line height using the key function:</p>
  
  <pre><code>&lt;xsl:value-of select="key('lookup.font-metrics.line-height',$font-size)"/&gt;
  </code></pre>
  
  <p>...however I am getting the following error message:</p>
  
  <pre><code>XPath error : Invalid expression
  //document('')//xsl:variable[@name='data.font-metrics.line-height'])/line-height/text()
             ^
  </code></pre>
  
  <p>I think several problems are coming together here:</p>
  
  <ul>
  <li>use of the document function</li>
  <li>use of the key function</li>
  <li>what is the best method of embedding XML? in a variable?</li>
  </ul>
  
  <p>There may also be a completely different solution to the problem.</p>
  
  <p>I would be very grateful of your help!</p>