XSLT 3.0 fn:document() throws error on 404 not found while XSLT 2.0, 1.1, and 1.0 did not (Saxon-JS)

133 views Asked by At

The XSLT specification has always said that the document() and doc() functions MAY throw a dynamic error when the document cannot be loaded from the URL (e.g. 404 not found) and in the browser's XSLT processors as well as Saxon (the version I keep using even after a decade is 8.1.1) usually that has all been that way. But now trying Saxon-JS, I see an exception is thrown. Now I need to use the new fn:doc-available function which, however, isn't in XSLT/XPath 2.0! So I have to break my backward compatibility of my XSLT code because of that new super-strict behavior.

Is there some option in Saxon-JS where the old behavior of fn:document can be selected as an option?

1

There are 1 answers

1
Michael Kay On

In the case of the doc() function the spec is pretty clear that a dynamic error should be thrown (although a function like this that interacts with the external environment always leaves some scope for vendor interpretation).

For document() the error handling has always been at vendor option. If an error occurs, the processor has the option of not reporting the error, but simply returning nothing. In Saxon on the Java platform, we've chosen to delegate the choice to the user as a configuration option. It's difficult to trace 20 years of history, but I think it's entirely likely that the default has changed at some point in time; certainly in modern Saxon releases, the default is to throw the error, and now that try/catch is available in 3.0 this certainly seems the most appropriate choice.

For SaxonJS, keeping the product small and simple is desirable, and we want to have as few configuration options as possible. Given that the "recovery" option here exists only for backwards compatibility, and that the requirement can be met using try/catch (or doc-available()), it seems unnecessary to provide another way of controlling it.