initial-function parameters are not type-checked
Stylesheeets can be invoked through execution of an initial stylesheet function using the
functionParams options of
Internally the transform finds the function declaration, sets the given parameters into the local variable slot frame and then executes the sequence constructor body of the function. In the process the types of the presented parameter values are not checked. Thus for example executing:
<xsl:function name="f:bar> <xsl:param name="a" as="xs:integer"/> <xsl:sequence select="2 * $a"/>
xs:string("foo") will result in a thrown (non XError) error as the
rhs.toNumber() function does not exist for
xs:string when the integer * integer calculation is performed. Equally well valid promotion or casting is not carried out, so for example
"http://saxon.sf.net/" passed to a parameter typed as
xs:anyURI would not be converted and subsequent code may fail.
In the case of parameters passed through
The arguments in the function declaration do have type annotations in an
@as attribute, but this is not used at run time in SaxonJS.
To correct this would require some generic type-checking mechanism in SaxonJS invoked in the initial-function section of
transform(). The XPath compiler contains code that may be adaptable but which is currently targetted to generating potential type-check/conversion code rather than actually carrying out the check or conversion. It would require module separation to enable it to be used independently of dynamic XPath evaluation, which is designed to be a separately loadable module.
#4 Updated by Michael Kay about 2 months ago
- Status changed from New to Closed
- Fixed in JS Release set to Saxon-JS 2.0
I've written a series of API tests async-trans-018a...i to test initialFunction invocation using parameters with and without conversion, including error cases. No problems found, so I'm closing the bug.
Please register to edit this issue