Project

Profile

Help

Collation URI for sort in SaxonJS.XPath.evaluate

Added by Alf Eaton 10 months 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 9 months 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 Debbie Lockett 8 months 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 6 months 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 6 months 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 6 months 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 6 months 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.

    (1-7/7)

    Please register to reply