Ticket #461 (closed defect: fixed)
XSLTUtil's URIResolver resolves unresolvable URIs wrongly and ignores base
Description
I think I understood why we're getting strange XSLT error messages with some OMDoc input documents. These documents contain broken links (e.g. to images, via omlet/data). Inside the OMDoc XSLTs, these links are resolved using the document(uri) function, whose result is an XML document. When a non-default URIResolver is in operation, and we need such a thing for JOMDoc in some cases (#432 or TNTBase future), you (Dimitar) should know one more thing I think I haven't told you (shame on me for that): It is not only invoked for resolving xsl:include (i.e. paths to other XSLTs relatively to the current XSLT document), but also for document() (i.e. for resolving URIs relatively to the URI of the current document).
Now that is what the base argument of the resolve document is important for, which we have ignored so far in the URIResolver implementation of XSLTUtil. (Ceterum censeo: Use a smarter URIResolver!) Every document D that we deal with has a notion of its URI (the "system ID" that I mentioned before). When a URI relative to D is to be resolved, that system ID is passed as base to the URIResolver. That means that the URIResolver itself also has to set a reasonable system ID for any Source that it returns, otherwise relative URIs from that document won't be resolved correctly. This all works smoothly if we are in the file system and using the default URI resolver (i.e. don't set our own one).
Now for the return value of resolve. It may well be the case that a certain URI is not resolvable. For the case of resolving an xsl:include that is not desirable, but shit happens. But for the case of document(), it is quite common, because there it was the author of the document who placed a dangling link there -- with or without his own fault. When a URI target does not exist, URIResolver.resolve is supposed to return null, but the XSLTUtil URIResolver does not. It returns new StreamSource?(null), and that gives us nice, almost incomprehensible error message that appear to come from the XSLTs, because then the XSLT processor (Saxon) tries to parse the empty StreamSource? into an XML document, but does not find an XML document in that place. The error messages are then like "non-wellformed input", "invalid character at position 1, line 1", or similar.
