Bug #1903
closedsaxon:key-map appears to default to open-ended "max" value when no keys satisfy given range.
100%
Description
Scenario:
$key is a key enabled with saxon:range-key="true", and $key has no entries in the range $min to $max for document $doc
Expected behavior: saxon:key-map($key, $doc, $min, $max) returns an empty map.
Actual behavior: saxon:key-map($key, $doc, $min, $max) returns all entries whose key values are above $min.
Reproducible: The following script, when processed by Saxon 9.5.0.2 returns the output
1 2
9
The "9" is unexpected. I searched saxonica.plan.io for tickets associated to saxon:key-map() and did not find any, so I assumed this has not been resolved.
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:saxon="http://saxon.sf.net/"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
>
<xsl:key name="key" match="cars/car" use="@id" saxon:range-key="yes"/>
<xsl:variable name="car.doc">
<cars>
<car id="1"/>
<car id="2"/>
<car id="3"/>
<car id="9"/>
</cars>
</xsl:variable>
<xsl:variable name="seq" select="0,1,2,3,4,5"/>
<xsl:template match="/">
<xsl:text>
</xsl:text>
<xsl:variable name="map1" select="saxon:key-map('key',$
car.doc,'0','2')"/>
<xsl:value-of select="map:keys($map1)"/>
<xsl:text>
</xsl:text>
<xsl:variable name="map2" select="saxon:key-map('key',$car.doc,'5','8')"/>
<xsl:value-of select="map:keys($map2)"/>
</xsl:template>
</xsl:stylesheet>
Files
Updated by O'Neil Delpratt about 11 years ago
- Status changed from New to In Progress
- Assignee set to O'Neil Delpratt
- Priority changed from Low to Normal
Thanks very much for reporting the problem you have discovered. We are investigating it now.
Updated by O'Neil Delpratt about 11 years ago
- Found in version changed from 9.5.0.2 to 9.5
I have managed to reproduce the bug reported. I also noticed a separate problem. Running the stylesheet under Saxon-EE (i.e. with the option '@-sa@') produces the following error:
Error on line 23 of keymap.xsl:
Key definition key has non-string key values
Transformation failed: Run-time errors were reported
Updated by O'Neil Delpratt about 11 years ago
- % Done changed from 0 to 100
Bug fixed and applied to subversion
The fix was made in the next
method of the Iterator class RangeKey@. The problem was that we were not checking the next value against the @max
key after filtered out values less than the min
key.
Fix will appear in the next maintenance release.
The other issue is the error message mentioned in comment #3 which occurs as a result of using the option '-sa'. We believe that this is reasonable outcome because with the '-sa' option we are say to run as schema aware. The type at compile time is @anyAtomicType@, we cannot make any assumptions on the type of the key '@id@' being a string or untypedAtomic, therefore the exception is thrown.
As a workaround when the option '-sa' is required we can do the following:
<xsl:key name="key" match="cars/car" use="xs:string(@id)" saxon:range-key="yes"/>
Updated by O'Neil Delpratt almost 11 years ago
- Status changed from In Progress to Closed
- Fixed in version set to 9.5.1.3
Bug fix applied in Saxon maintenance release 9.5.1.3
Updated by O'Neil Delpratt about 10 years ago
Bug also fixed in the Saxon9.6 development branch. Test added to Saxon 9.6 JUnit tests
Please register to edit this issue