Collation URI for sort in SaxonJS.XPath.evaluate
Added by Alf Eaton about 3 years ago
I was hoping to be able to specify a collation URI as the second parameter to fn:sort
when using SaxonJS.XPath.evaluate
, but it seems to throw an error: "Cannot read properties of null (reading 'toString')".
For example:
sort(//ref/@id ! tokenize(., '\s'), 'http://saxon.sf.net/collation?alphanumeric=yes')
or
sort(//ref/@id ! tokenize(., '\s'), 'http://www.w3.org/2013/collation/UCA?numeric=yes')
Is this the right way to apply a collation URI to a sort?
Replies (7)
Please register to reply
RE: Collation URI for sort in SaxonJS.XPath.evaluate - Added by Alf Eaton about 3 years ago
Here's a more straightforward example:
sort(('C', 'A', 'B'))
=> correctly sorts the list
sort(('A', 'B', 'C'), 'http://www.w3.org/2013/collation/UCA?numeric=yes')
=> Cannot read properties of null (reading 'toString')
RE: Collation URI for sort in SaxonJS.XPath.evaluate - Added by Michael Kay about 3 years ago
I've logged this as a bug here: https://saxonica.plan.io/issues/5162
RE: Collation URI for sort in SaxonJS.XPath.evaluate - Added by Debbie Lockett almost 3 years ago
Alf, which version of SaxonJS are you using? And could you provide more details of your invocation? I have not been able to reproduce your error with SaxonJS 2 in the browser. For instance the following produces the expected result:
SaxonJS.XPath.evaluate("sort(('C', 'A', 'B'), 'http://www.w3.org/2013/collation/UCA?numeric=yes')");
RE: Collation URI for sort in SaxonJS.XPath.evaluate - Added by Alf Eaton almost 3 years ago
I'm using saxon-js v2.3.0 - here's a minimal example:
import SaxonJS from 'saxon-js'
const doc = await SaxonJS.getResource({ text: '<test/>', type: 'xml' })
const selector =
"sort(('C', 'A', 'B'), 'http://www.w3.org/2013/collation/UCA?numeric=yes')"
const result = SaxonJS.XPath.evaluate(selector, doc)
console.log(result)
Here's a demo in CodeSandbox.
RE: Collation URI for sort in SaxonJS.XPath.evaluate - Added by Debbie Lockett almost 3 years ago
Thanks! OK, I've now been able to reproduce your issue. Very strange that this occurs when calling SaxonJS.XPath.evaluate
in Node.js, but not in the browser (and also not an issue when using the -xp
command line option). Please follow https://saxonica.plan.io/issues/5162 for bug updates.
RE: Collation URI for sort in SaxonJS.XPath.evaluate - Added by Alf Eaton almost 3 years ago
The CodeSandbox demo is actually running in the browser - see the output by itself here.
RE: Collation URI for sort in SaxonJS.XPath.evaluate - Added by Debbie Lockett almost 3 years ago
Indeed. I meant the difference between SaxonJS built for Node.js and for the browser: you're using the Node.js version of SaxonJS.
Please register to reply