Potentially undocumented change in XML parsing behaviour between Saxon 9.5.1 and Saxon 9.6
When upgrading from Saxon 22.214.171.124 to Saxon 126.96.36.199 my project started generating the following error (full exception at end) when attempting to load an imported/included nested stylesheet.
Error reported by XML parser processing anonymised-script.xsl: FWK005 parse may not be called while parsing.
This appeared to be caused by setting a URI Resolver on an XsltCompiler that returns an InputStream based SAXSource for imported/included XSL stylesheets, where the SAXSource explicitly sets an XMLReader (to the XML reader/parser used during the parsing of the original, non-nested, stylesheet). Commenting out the explicit setting of the XMLReader on the imported/included nested stylesheet invocations fixed this issue. However, the URI resolver now fetches the nested stylesheets twice rather than once (according to my debug messages in he URI resolver implementation). Is this supposed to happen?
I have not noticed a release note (or other documentation, forum discussion, etc.) that discusses a change in behaviour for the loading of nested stylesheets or URI resolving. And was wondering if the new behaviour was an unintended side-effect of another change?
Note the reason that the XMLReader was explicitly set in each case was: to ensure that the XML parser used to load a top-level stylesheet was also used to load the imported/included nested stylesheets. Does commenting out this explicit setting of the XMLReader ensure that the original stylesheet XML parser is used to load the nested stylesheets (in both Saxon 9.5.1 and 9.6)?
I hope this message is clear and contains some useful observations.
Best regards, Anthony.
PS: an anonymised version of the exception and its stack trace is now follows. Here the names of the stylesheets and application classes have been anonymised.
Error Error reported by XML parser processing anonymised.xsl: FWK005 parse may not be called while parsing. Exception in thread "main" net.sf.saxon.s9api.SaxonApiException: Error reported by XML parser processing anonymised .xsl: FWK005 parse may not be called while parsing. at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:546) at anonymised.Anonymised.runXslScriptFromResource(Anonymised.java:330) at anonymised.Anonymised.main(Anonymised.java:62) Caused by: net.sf.saxon.trans.XPathException: Error reported by XML parser processing anonymised.xsl: FWK005 parse may not be called while parsing. at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:454) at net.sf.saxon.event.Sender.send(Sender.java:145) at net.sf.saxon.style.StylesheetModule.loadStylesheetModule(StylesheetModule.java:128) at net.sf.saxon.style.UseWhenFilter.startElement(UseWhenFilter.java:341) at net.sf.saxon.event.StartTagBuffer.startContent(StartTagBuffer.java:220) at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:178) at net.sf.saxon.event.ProxyReceiver.startContent(ProxyReceiver.java:178) at net.sf.saxon.event.ReceivingContentHandler.startElement(ReceivingContentHandler.java:356) at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source) at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:440) at net.sf.saxon.event.Sender.send(Sender.java:145) at net.sf.saxon.style.StylesheetModule.loadStylesheetModule(StylesheetModule.java:128) at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:131) at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:94) at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:543) ... 2 more Caused by: org.xml.sax.SAXException: FWK005 parse may not be called while parsing. at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:440) ... 24 more
RE: Potentially undocumented change in XML parsing behaviour between Saxon 9.5.1 and Saxon 9.6 - Added by Michael Kay almost 6 years ago
Yes, there has been a change. In previous releases a stylesheet module was parsed to a tree representation, and then the xsl:include and xsl:import element were found on the tree, and sent for parsing, so only one parse would be in progress at a time. This strategy needed to be changed to handle static variables in XSLT 3.0. The use-when attribute has always been applied during parsing, so when use-when is false, the relevant instructions are filtered out and never appear on the stylesheet tree. In XSLT 3.0 use-when expressions can refer to static variables, and the value of a static variable can be affected by processing of included/imported stylesheet modules, so xsl:include and xsl:import are now actioned earlier, during the parsing of the parent stylesheet. It hadn't occurred to me that this could affect applications supplying their own URIResolver.
Internally Saxon attempts to reuse the stylesheet parser if it can, but it effectively keeps track of whether a parser is in use, and doesn't attempt to reuse it until it is returned to the pool at the end of parsing. The SAX specification is clear that an XMLReader is serially reusable, but you can't commence one parse while a previous one is unfinished.
Please register to reply