[xsl] Re: Saxon-CE -- Passing Data to a JS Function

Subject: [xsl] Re: Saxon-CE -- Passing Data to a JS Function
From: "Philip Fearon pgfearo@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Jul 2016 12:03:33 -0000
As you've already found, passing data from Saxon-CE XSLT to a JS
function requires some extra care. Firstly, it really helps to
explicitly cast a value to the type expected in the JS function,
either by passing in a typed variable (as you've done) or wrapping the
argument in a cast expression - e.g. xs:string(@value).

There shouldn't be a problem passing an XML node, or sequence of nodes
to a JS function. Saxon-CE (if memory serves) manages nodes internally
as compatible DOM nodes, these are just wrapped for the purpose of
XSLT processing.

One suggestion - it is possible to pass JS object literals back and
forth from Saxon-CE to JS functions. This might be easier than
constructing a JSON string.

Note that you may experience problems when passing empty sequences as
JS function parameters, to avoid confusion I often deliberately add a
dummy item to the start of a sequence in Saxon-CE, and then simply
ignore this first item on the JS side.

Phil Fearon

Current Thread