Issue found in XSLT runner key() function
- From: Erik Balgård <Erik.Balgard@smidja.se>
- To: "issues@odftoolkit.odftoolkit.org" <issues@odftoolkit.odftoolkit.org>
- Subject: Issue found in XSLT runner key() function
- Date: Mon, 14 Sep 2009 12:01:55 +0200
Hello.
While working with ODF XSLT runner program i have run into a problem
with the key() function.
In this case i need to import an second xml file besides the input xml
(using the document() function) and then use the key function to get the
correct values from it.
I found a tutorial that does exaclty what i want to do but
unfortionately this does not work as intended on ODF XSLT runner.
The link to the tutorial an be found Here
<http://www.xml.com/pub/a/2002/03/06/xslt.html> (the third example is
the relevant one in this case). For future reference i will duplicate
the code here aswell.
*Input xml, xq484.xml:*
<shirts>
<shirt colorCode="c4">oxford button-down</shirt>
<shirt colorCode="c1">poly blend, straight collar</shirt>
<shirt colorCode="c6">monogrammed, tab collar</shirt>
</shirts>
*Document imported with document(), xq485.xml:
<colors>
<color cid="c1">yellow</color>
<color cid="c2">black</color>
<color cid="c3">red</color>
<color cid="c4">blue</color>
<color cid="c5">purple</color>
<color cid="c6">white</color>
<color cid="c7">orange</color>
<color cid="c7">green</color>
</colors>
*Input stylesheet, xq487.xsl:*
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:variable name="colorLookupDoc" select="document('xq485.xml')"/>
<xsl:key name="colorNumKey" match="color" use="@cid"/>
<xsl:template match="shirts">
<xsl:apply-templates select="$colorLookupDoc"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="colors"/>
<xsl:template match="shirt">
<xsl:variable name="shirtColor" select="@colorCode"/>
<xsl:for-each select="$colorLookupDoc">
<xsl:value-of select="key('colorNumKey',$shirtColor)"/>
</xsl:for-each>
<xsl:text> </xsl:text><xsl:apply-templates/><xsl:text>
</xsl:text>
</xsl:template>
It is the key('colorNumKey',$shirtColor) call that does not seem to work correctly.
The document (xq485.xml) is imported correctly and the $shirtColor variable gets evalutated correctly (c4,c1,c6)
but the translation from the color codes to color words does not work. The result of the above code is just the contents
of the input xml striped of its tags without any color or color code added to each line.
I tried another xslt processor (Saxon HE 9.2.0.2 <http://saxon.sourceforge.net/>) and it worked great.
I'd love to continue to work with odf xslt runner since the final result will be an .odt document but function > convinience im afraid.
Erik Balgård
Smidja AB
|
Issue found in XSLT runner key() function |
Erik Balgård | 09/14/2009 |
| Svante Schubert | 09/14/2009 |

