This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 6164 - [XSLT] Description of compatibility mode for key function is ambiguous
Summary: [XSLT] Description of compatibility mode for key function is ambiguous
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 2.0 (show other bugs)
Version: Recommendation
Hardware: All All
: P4 minor
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL: http://www.w3.org/TR/xslt20/#keys
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-15 20:25 UTC by Henry Zongaro
Modified: 2009-01-30 15:25 UTC (History)
0 users

See Also:


Attachments

Description Henry Zongaro 2008-10-15 20:25:10 UTC
Consider this stylesheet

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:key name="mykey" match="pz" use="number()" version="1.0"/>
  <xsl:key name="mykey" match="nz" use="number()"/>

  <xsl:template match="/">
    <out><xsl:copy-of select="key('mykey',0)"/></out>
  </xsl:template>
</xsl:stylesheet>

applied to this input

<doc><pz>0</pz><nz>-0.0</nz></doc>

According to section 16.3.2 of XSLT 2.0[1] "if any of the xsl:key elements in the definition of the key enables backwards compatible behavior, then the value of the key specifier and the value of the second argument of the key function are both converted after atomization to a sequence of strings, by applying a cast to each item in the sequence, before performing the comparison."

It's unclear to me from that description whether the conversions to sequences of strings occurs only for the values of the key specifiers of those xsl:key elements that enable backwards compatible behaviour and comparison with those specifiers, or for the key specifiers of all the xsl:key elements for that key, if at least one enables backwards compatible behaviour.

If the former was intended, the value of the key specifier for pz and nz would be cast to sequences of string - '0' for pz and '-0' for nz - the second argument of key would be cast to the string '0'.  Only the key specifier for pz would match, and the result of the above stylesheet would be

<?xml version="1.0"?><out><pz>0</pz></out>

If the latter reading was intended, the value of the key specifier for pz would be cast to the string '0' as would the value of the second argument in comparing with that key specifier, so pz would be selected.  The value of the key specifier for nz - the xs:double value -0.0 - would be compared to the value of the second argument - the xs:integer value 0 - and so nz would also be selected.  The result would be

<?xml version="1.0"?><out><pz>0</pz><nz>-0</nz></out>

If it helps, the description of the backwards compatible behaviour first appeared in the working draft of 11 February 2005.[2]  I couldn't find any discussion in the mail archives of this particular aspect of backwards compatibility after a brief search.

[1] http://www.w3.org/TR/xslt20/#keys
[2] http://www.w3.org/TR/2005/WD-xslt20-20050211
Comment 1 Michael Kay 2008-10-15 20:43:29 UTC
The intention was certainly that either the entire key definition operates in backwards compatibility mode or none of it does, and that it should operate in BC mode if at least one of the xsl:key declarations is in BC mode. But you might be right that the wording could be clarified.
Comment 2 Michael Kay 2009-01-30 12:46:27 UTC
A clarifying erratum E33 has been drafted (and will soon be available for internal review). I am therefore marking the bug report as fixed. Henry, when you have reviewed the erratum, if you are satisfied with it please mark the bug as closed.
Comment 3 Henry Zongaro 2009-01-30 15:25:04 UTC
I'm happy with the changes in E33.