Bug #4818
closedfn:sort with three arguments gives error TypeError: d.compareTo is not a function
100%
Description
I have run into an issue with fn:sort
and Saxon-JS 2, when I use <xsl:sequence select="sort(date, (), function($d) { $d })"/>
I get an error TypeError: d.compareTo is not a function
. Tested with Saxon-JS 2.0 from Saxonica Node.js version v12.18.0.
Sample:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="root">
<xsl:copy>
<xsl:sequence select="sort(date, (), function($d) { $d })"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/" name="xsl:initial-template">
<xsl:next-match/>
<xsl:comment xmlns:saxon="http://saxon.sf.net/">Run with {system-property('xsl:product-name')} {system-property('xsl:product-version')} {system-property('Q{http://saxon.sf.net/}platform')}</xsl:comment>
</xsl:template>
</xsl:stylesheet>
Input sample:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<date>2020-11-03+02:00</date>
<date>2020-11-01+02:00</date>
<date>2020-11-02+02:00</date>
<date>2020-11-05+02:00</date>
<date>2020-11-04+02:00</date>
<date>2020-11-06+02:00</date>
</root>
The above is a reduced sample and using the straightforward one argument sort(date)
works but in the original sample I needed the three argument form e.g. sort(foo, (), function($f) { $f/bar })
and got the same error.
Updated by Michael Kay almost 4 years ago
As a workaround, try atomizing the value:
select="sort(date, (), function($d) { string($d) })"
I think we should probably be doing this automatically: I need to check the rules on function coercion in the spec to be sure.
Updated by Michael Kay almost 4 years ago
- Status changed from New to Resolved
- Fix Committed on JS Branch Trunk added
The test is working under the current development code, though I have reproduced the failure with 2.0 as issued.
We've done quite a bit of extra testing and bug fixing since the release, so I think we must have fixed this one, but I haven't been able to find a specific record of the change. I think it's been fixed in the XX compiler, which now generates the function coercion code.
I'm going to mark it as resolved.
Updated by Community Admin over 3 years ago
- Applies to JS Branch 2 added
- Applies to JS Branch deleted (
2.0)
Updated by Debbie Lockett over 3 years ago
- Fix Committed on JS Branch 2 added
- Fix Committed on JS Branch deleted (
Trunk)
Updated by Debbie Lockett over 3 years ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in JS Release set to Saxon-JS 2.1
Bug fix applied in the Saxon-JS 2.1 maintenance release.
Please register to edit this issue
Also available in: Atom PDF Tracking page