Project

Profile

Help

Problem with using || operator on a mixture of nodes and strings

Added by Martin Honnen about 7 years ago

I have run into various problems with Saxon-JS when trying to use some XPath 3.1 features, when I have a simple XPath expression

cities/city!(@country || ', ' || @name)

and execute that against an XML input (taken from the XSLT 3.0 spec)



  
    
  
      
  
  

I don't get the expected sequence of string values but rather a sequence of @"[object Object], [object Object]"@ respectively on the Javascript side an array of


[
	"[object Object], [object Object]",
	"[object Object], [object Object]",
	"[object Object], [object Object]",
	"[object Object], [object Object]",
	"[object Object], [object Object]",
	"[object Object], [object Object]"
]

An online sample is at https://martin-honnen.github.io/js/2017/grouping-with-xpath31-maps10.html.

The complete, original code I have is at https://martin-honnen.github.io/js/2017/grouping-with-xpath31-maps3.html, this does not work at all but throws an exception


Uncaught TypeError: Cannot read property 'length' of undefined
    at Ea (eval at load (SaxonJS.min.js:7), :5:4154)
    at Ea (eval at load (SaxonJS.min.js:7), :5:4314)
    at Ea (eval at load (SaxonJS.min.js:7), :5:4314)
    at Ea (eval at load (SaxonJS.min.js:7), :4:29213)
    at ya (eval at load (SaxonJS.min.js:7), :5:4421)
    at ia (eval at load (SaxonJS.min.js:7), :4:8403)
    at la (eval at load (SaxonJS.min.js:7), :4:9639)
    at Object.evaluate (SaxonJS.min.js:7)
    at grouping-with-xpath31-maps3.html:25
    at XMLHttpRequest.req.onload (grouping-with-xpath31-maps3.html:12)

I am not sure whether that is solely because of the problem with @||@ or whether there are other problems involved but the exception seems a bug in Saxon-JS as well as the code

let $comp-key := function($city) { $city/@country || ', ' || $city/@name }
return 
  for $key in cities/city!$comp-key(.)=>distinct-values()
  return
    let $group := cities/city[$key = $comp-key(.)]
    return 
      map { $key : avg($group/@pop) }

works fine when run with Saxon Java.


Replies (3)

Please register to reply

RE: Problem with using || operator on a mixture of nodes and strings and with anonymous function - Added by Martin Honnen about 7 years ago

It seems the exception in the second document is caused by the use of an anonymous function, as with https://martin-honnen.github.io/js/2017/let-fun-return-seqt1.html which solely does

let $comp-key := function($city) { concat($city/@country, ', ', $city/@name) }
return cities/city!$comp-key(.)

the exception already occurs, without using @||@ or maps.

Here is the trace I get in Chrome:

Uncaught TypeError: Cannot read property 'length' of undefined
    at Ea (eval at load (SaxonJS.min.js:7), :5:4154)
    at Ea (eval at load (SaxonJS.min.js:7), :5:4314)
    at Ea (eval at load (SaxonJS.min.js:7), :5:4314)
    at Ea (eval at load (SaxonJS.min.js:7), :4:29213)
    at ya (eval at load (SaxonJS.min.js:7), :5:4421)
    at ia (eval at load (SaxonJS.min.js:7), :4:8403)
    at la (eval at load (SaxonJS.min.js:7), :4:9639)
    at Object.evaluate (SaxonJS.min.js:7)
    at let-fun-return-seqt1.html:25
    at XMLHttpRequest.req.onload (let-fun-return-seqt1.html:12)

Firefox also fails, though with a slightly different error:

TypeError: cc is undefined[Learn More]  SaxonJS.min.js%20line%207%20%3E%20eval:5:4150
	Ea https://martin-honnen.github.io/Saxon-JS-1.0.0/SaxonJS.min.js%20line%207%20%3E%20eval:5:4150
	Ea https://martin-honnen.github.io/Saxon-JS-1.0.0/SaxonJS.min.js%20line%207%20%3E%20eval:5:4314
	Ea https://martin-honnen.github.io/Saxon-JS-1.0.0/SaxonJS.min.js%20line%207%20%3E%20eval:5:4314
	Ea https://martin-honnen.github.io/Saxon-JS-1.0.0/SaxonJS.min.js%20line%207%20%3E%20eval:4:29213
	ya https://martin-honnen.github.io/Saxon-JS-1.0.0/SaxonJS.min.js%20line%207%20%3E%20eval:5:4421
	ia https://martin-honnen.github.io/Saxon-JS-1.0.0/SaxonJS.min.js%20line%207%20%3E%20eval:4:8403
	la https://martin-honnen.github.io/Saxon-JS-1.0.0/SaxonJS.min.js%20line%207%20%3E%20eval:4:9639
	SaxonJS https://martin-honnen.github.io/js/2017/let-fun-return-seqt1.html:25:21
	load/req.onload https://martin-honnen.github.io/js/2017/let-fun-return-seqt1.html:12:5

IE and Edge also give similar errors.

RE: Problem with using || operator on a mixture of nodes and strings - Added by Michael Kay about 7 years ago

Thanks for the info. Saxon-JS doesn't support the higher order function option (including inline functions, dynamic calls, etc), and we are working on detecting the error at export time if you export a stylesheet with target:JS.

Longer term I would love to support HOF in Saxon-JS, but that will have to wait a bit.

    (1-3/3)

    Please register to reply