I've long made do with the default XML libraries provided by Java (Xerces2-J and Xalan-J) - occasionally and directly using the latest versions of those libraries when needed. It appears I'm running up against some of the limits of these libraries - especially with Xalan-J that is really no longer being maintained and without a release for almost 6 years...
I need to provide some custom functions to pull information from external services when called, so they must be implemented in Java. (i.e. I can't implement them within the XSLT itself, as either XSLT or JavaScript functions, etc.) I've done this before using Xalan-Java Extensions. However, providing this seems to be either allow-all or nothing:
- http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200911/msg00198.html
- http://marc.info/?l=xalan-j-users&m=123750821029013
- https://issues.apache.org/jira/browse/XALANJ-1850
I need to be able to provide access to a Java extension - but without allowing any arbitrary calls out to Java (think of an embedded call to System.exit()
, for example), and ideally, without the XSLT authors even needing to know that it is a Java function (by use of xmlns:java="http://xml.apache.org/xalan/java"
, for example). Ideally, I'd also be able to keep TransformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
.
I can do (almost) exactly what I'm looking for using XPath.setXPathFunctionResolver
, but this only works for direct XPath calls - and I've not found a way to set a custom XPath for use in XSLT by Xalan. (It also requires the FEATURE_SECURE_PROCESSING
to not be set on the XPathFactory
, though I might be able to get away with having it set only on the TransformerFactory
- ignoring that if set on the TransformerFactory, the TransformerFactory also automatically sets the same flag on the XPathFactory that is uses.)
So I decided to give Saxon (Saxon-HE 9.5.1-1) a try - and am immediately noticing 2 issues:
When just using XPath directly,
XPath.setXPathFunctionResolver
does not seem to have any affect under Saxon. Theset
call completes without issue, butresolveFunction
on the passed-inXPathFunctionResolver
is never even called under Saxon. (It simply "just works" under Xalan.) Is there some additional configuration necessary for Saxon - or is this maybe a limitation of the HE version?I've looked at http://www.saxonica.com/documentation/#!extensibility/integratedfunctions/ext-simple-J - which per the author, is provided for even under the HE version. It also looks to be exactly what I need - however (like with(This is answered by the XALAN register Extension Function like in SAXON in the question itself.)XPathFunctionResolver
under Xalan), I can't see how to wire this into XSLT processing.