As reported by Martin, the failure with SaxonJS 2 is different:
xslt3 -t -s:Downloads\evaluationTest.xml -xsl:Downloads\validation.xslt
SaxonJS 2.5 from Saxonica
Node.js version v16.17.1
Compiling stylesheet C:\Users\marti\Downloads\validation.xslt
Stylesheet compilation time: 0.249s
Asynchronous transform with options: stylesheetText={"N":"package","version":"20",(string), stylesheetBaseURI=file://C:/Users/marti/Download(string), stylesheetParams=[object Object](string), outputProperties=[object Object](string), extraOptions=[object Object](string), destination=stdout(string), baseOutputURI=file://C:/Users/marti/(string), logLevel=2(string), sourceFileName=file://C:/Users/marti/Download(string),
SEF generated by SaxonJS 2.5 at 2023-05-01T22:27:47.954+02:00
in root of document
<?xml version="1.0" encoding="UTF-8"?>
<innings>
<number>1</number>
<battingSide>yorkshire</battingSide>
<fieldingSide>lancashire</fieldingSide>
<over>
<bowler>1</bowler>Transformation failure: Error XTTE0570 at validation.xslt#39
Required item type of value in 'xsl:variable name="Q{}read_function"' expression is (function(element(*)) as element(*)?); supplied value is anonymous function (arity 1)
Error XTTE0570 at validation.xslt#39
Required item type of value in 'xsl:variable name="Q{}read_function"' expression is (function(element(*)) as element(*)?); supplied value is anonymous function (arity 1)
And in fact, this error is correct, though the error message does not give quite enough information to make this clear. The supplied anonymous function will not pass the type checking because its function type is not a subtype of function(element(*)) as element(*)?
The signature of the supplied anonymous function is either function(element(innings)) as element(side)
or function(element(over)) as element(player)
, as specified in the function declarations in the source evaluationTest.xml.
But for function types, function(A) as B
is a subtype of function(C) as (D)
requires that B
is a subtype of D
, and C
is a subtype of A
, not the other way round (see https://www.w3.org/TR/xpath-31/#id-sequencetype-subtype).