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.
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:
<xsl:variable name="data.font-metrics.line-height">
<line-height font-size="11">12</line-height>
<line-height font-size="12">14</line-height>
<line-height font-size="13">15</line-height>
<line-height font-size="14">16</line-height>
<line-height font-size="15">17</line-height>
<line-height font-size="16">18</line-height>
<line-height font-size="17">20</line-height>
<line-height font-size="18">21</line-height>
</xsl:variable>
<xsl:key name="lookup.font-metrics.line-height" match="document('')//xsl:variable[@name='data.font-metrics.line-height'])/line-height" use="@font-size"/>
After that, I should be able to lookup a line height using the key function:
<xsl:value-of select="key('lookup.font-metrics.line-height',$font-size)"/>
...however I am getting the following error message:
XPath error : Invalid expression
//document('')//xsl:variable[@name='data.font-metrics.line-height'])/line-height/text()
^
I think several problems are coming together here:
- use of the document function
- use of the key function
- what is the best method of embedding XML? in a variable?
There may also be a completely different solution to the problem.
I would be very grateful of your help!