This works for me:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="language-table">
<name code="ar">ARABIC</name>
<name code="de">GERMAN</name>
<name code="en">ENGLISH</name>
<name code="zh">CHINESE</name>
</xsl:variable>
<xsl:key name="language-code" match="name" use="@code"/>
<xsl:template match="/">
<xsl:variable name="stylesheet" select="document('')"/>
<xsl:value-of select="key('language-code', 'de', $stylesheet)"/>
</xsl:template>
</xsl:stylesheet>
run against itself outputs
GERMAN
As DC said, though, document('') is inefficient and in 2.0 is never
necessary.
key('language-code', 'de', $language-table)
gives the same result and is much more efficient.
Michael Kay
http://www.saxonica.com/
-----Original Message-----
From: Kevin Rodgers [mailto:kevin(_dot_)rodgers(_at_)ihs(_dot_)com]
Sent: 17 February 2005 16:44
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] keyed lookup table
I've got a working lookup table implemented like this:
<xsl:variable name="language-table">
<!-- See ISO 639 -->
<name code="ar">ARABIC</name>
<name code="de">GERMAN</name>
<name code="en">ENGLISH</name>
...
<name code="zh">CHINESE</name>
</xsl:variable>
that I can access in my templates with an expression like:
$language-table/name[(_at_)code='de']
I was hoping I could access that table via a key:
<xsl:key name="language-code" match="name" use="@code"/>
that I would access with this expression:
key('language-code', 'de', $stylesheet)"/>
given:
<xsl:variable name="stylesheet" select="document('')"/>
But the key function always returns an empty sequence. Why?
Can I use
a key on these $language-table/name nodes, which are internal to the
stylesheet? (I'm sure it will work if I move the lookup
table from the
stylesheet to its own external XML document, which is more
maintainable
anyway, but I want to udnerstand what is wrong with the idea
of a keyed
lookup table within the stylesheet.)
Thanks,
--
Kevin
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--