Saxon's implementation of the JAXP API is not working correctly with schema-aware expressions.
(Note, this interface is not recommended for schema-aware XPath processing: the JAXP API is designed primarily for XPath 1.0, and it cannot be used in a portable way with XPath 2.0 as it does not support features like schema-awareness. The s9api interface is recommended instead. Nevertheless, this interface is supported, and bugs will be fixed.)
In Saxon 9.2, schema-awareness is a property of an excecutable, and should be enabled by default if a schema is imported into the static context. When the method XPathEvaluator.importSchema() is called, therefore, the executable should be marked as schema-aware, but this is not happening. In consequence, the XPath compiler makes incorrect static type inferences, typically assuming that data will be untyped when it is not, and this may result in spurious compile-time type errors, or in incorrect code being generated which might for example crash at runtime with a ClassCastException.
A patch is being applied, in the 9.2 branch only, to module JAXPXPathStaticContext.
This problem prevents the sample application XPathExampleSA from working. There are other problems with this sample application, and a new version is therefore being provided as an attachment to this bug entry. These problems are:
(1) the program tests xpf.getFeature("http://saxon.sf.net/feature/schema-validation") to determine if the processor is schema-aware. However, this is the wrong test. The test fails, because it is actually checking whether strict schema validation has been requested (which it has not).
(2) the program issues a query which, when used with the sample books.xml data file, selects no data and therefore returns an empty result. This is because the query is written to find books published in the 12 months before the current data, and there are no such books in the sample data.
(3) when this problem is corrected, the expression calls a user-defined extension function. The calling conventions for user-defined functions in the JAXP XPath interface are not well defined, either in the JAXP documentation or in the Saxon documentation. This function is expecting the arguments to be supplied in a different format from that actually provided. I will do further work to clarify the rules here.