Re: Issue found in XSLT runner key() function

  • From: Svante Schubert <Svante.Schubert@Sun.COM>
  • To: Erik.Balgard@smidja.se, Michael Brauer - Sun Germany - ham02 - Hamburg <Michael.Brauer@Sun.COM>
  • Cc: issues@odftoolkit.odftoolkit.org
  • Subject: Re: Issue found in XSLT runner key() function
  • Date: Mon, 14 Sep 2009 13:51:13 +0200

Hi Erik,

thanks for the report. Michael Brauer, who is the owner of the ODF XSLT runner program, is currently on vacation and will return next week.
He will take handle your request and perhaps even enable an issue tracking for odftoolkit, as an issue seems quite appropriate to your report.

Best regards,
Svante


Erik Balgård wrote:
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

Re: Issue found in XSLT runner key() function

Svante Schubert 09/14/2009
  • Powered by:
Terms of Use; Privacy Policy; Copyright ©2008-2010 (revision 20100521.d19488a)
 
 
loading
Please Confirm