Validation errors regarding XSLT (!) during XML transformation
Added by Franz Fackelmann over 3 years ago
My starting point was a properly working XSLT stylesheet. Transformation was set up in Java, no validation in the Saxon Configuration.
My intention was playing around with schema-ware XSLT features. I turned validation on in the Configuration, provided appropriate CatalogResolver and so on.
After successful compilation of my valid XSLT stylesheet xml-cc.xslt – ie. creation of the Templates with above Configuration –, Saxon issues following unexpected validation errors regarding the XSLT file.
Error on line 2 column 16 of xml-cc.xslt:
SXXP0003 Error reported by XML parser: Document is invalid: no grammar found.: Document
is invalid: no grammar found.
Error on line 2 column 16 of xml-cc.xslt:
SXXP0003 Error reported by XML parser: Document root element "xsl:stylesheet", must
match DOCTYPE root "null".: Document root element "xsl:stylesheet", must match DOCTYPE root "null".
Error on line 6 column 125 of xml-cc.xslt:
XTTE1512 Cannot validate <Q{.../Transform}stylesheet>: no element declaration available
Error on line 2928 column 18 of xml-cc.xslt:
XTTE1512 One validation error was reported: Cannot validate <Q{.../Transform}stylesheet>:
no element declaration available
One validation error was reported: Cannot validate <Q{.../Transform}stylesheet>: no element declaration available
One validation error was reported: Cannot validate <Q{.../Transform}stylesheet>: no element declaration available
; SystemID: file:/D:/projekte/Centris/trafo__SA/src/main/xslt/tf-data/xml-cc.xslt; Line#: 2928; Column#: 18
ValidationException: One validation error was reported: Cannot validate <Q{.../Transform}stylesheet>: no element declaration available
at net.sf.saxon.type.ValidationFailure.makeException(ValidationFailure.java:406)
at com.saxonica.ee.validate.ValidatingFilter.reportIfInvalid(ValidatingFilter.java:213)
at com.saxonica.ee.validate.ValidationStack.endElement(ValidationStack.java:525)
at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:148)
at net.sf.saxon.event.ProxyReceiver.endElement(ProxyReceiver.java:148)
at com.saxonica.ee.validate.AttributeInheritor.endElement(AttributeInheritor.java:62)
at net.sf.saxon.event.PathMaintainer.endElement(PathMaintainer.java:62)
at net.sf.saxon.event.DocumentValidator.endElement(DocumentValidator.java:78)
at net.sf.saxon.event.ReceivingContentHandler.endElement(ReceivingContentHandler.java:541)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(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 org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:439)
at net.sf.saxon.event.Sender.send(Sender.java:142)
at net.sf.saxon.functions.DocumentFn.makeDoc(DocumentFn.java:299)
at net.sf.saxon.functions.DocumentFn$DocumentMappingFunction.mapItem(DocumentFn.java:148)
at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:117)
at net.sf.saxon.om.SequenceIterator.forEachOrFail(SequenceIterator.java:135)
at net.sf.saxon.expr.sort.DocumentOrderIterator.<init>(DocumentOrderIterator.java:49)
at net.sf.saxon.functions.DocumentFn.call(DocumentFn.java:119)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:548)
at net.sf.saxon.expr.Expression.evaluateItem(Expression.java:852)
at net.sf.saxon.expr.parser.Evaluator$6.evaluate(Evaluator.java:173)
at net.sf.saxon.expr.SystemFunctionCall.evaluateArguments(SystemFunctionCall.java:454)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:546)
at net.sf.saxon.expr.Expression.process(Expression.java:949)
at net.sf.saxon.expr.SystemFunctionCall.process(SystemFunctionCall.java:481)
at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:754)
at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:142)
at net.sf.saxon.expr.instruct.DocumentInstr.evaluateItem(DocumentInstr.java:302)
at net.sf.saxon.expr.instruct.DocumentInstr.evaluateItem(DocumentInstr.java:45)
at net.sf.saxon.expr.parser.Evaluator$5.evaluate(Evaluator.java:151)
at net.sf.saxon.expr.parser.Evaluator$5.evaluate(Evaluator.java:148)
at net.sf.saxon.expr.LetExpression.eval(LetExpression.java:545)
at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:737)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:384)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:568)
at net.sf.saxon.trans.rules.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:72)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:530)
at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:661)
at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:360)
at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:349)
at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:74)
This is how the stylesheet basically starts (note: stylesheet is valid and all import / include / use-package are okay; for the packages I'm using an appropriate saxon-config.xml):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" exclude-result-prefixes="#all" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:z="urn:centris:trafo"
xmlns:cf="urn:centrisag:oms:trafo:fn" xmlns:tfu="urn:centrisag:oms:trafo:pkg:tf-util" xmlns:uuid="java:java.util.UUID"
xmlns:log="urn:centrisag:oms:trafo:pkg:log" xmlns:ccm="urn:centrisag:oms:trafo:pkg:cc-mod" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
xmlns:map="http://www.w3.org/2005/xpath-functions/map" xmlns:const="java:ch.centrisag.oms.trafo.transformation.Constants">
<xsl:import-schema schema-location="syr-norm.xsd"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:use-package name="urn:centrisag:oms:trafo:pkg:tf-util"/>
<xsl:use-package name="urn:centrisag:oms:trafo:pkg:cc-mod"/>
<xsl:use-package name="urn:centrisag:oms:trafo:pkg:log"/>
<xsl:import href="cmn/logger.xslt"/>
<xsl:import href="cmn/xml-cc-util.xslt"/>
<xsl:include href="cmn/xml-cc-doc.xslt"/>
<xsl:include href="cmn/xml-cc-ptnr.xslt"/>
...
Side note: When transforming an invalid (!) XML file with the same setup, the above validation messages regarding the stylesheet don't appear - just the correct validation messages related to the XML file being transformed.
Using the same Java program with another but similar XSLT stylesheet, these unexpected messages didn't appear and transformation ran successfully. One difference I'm aware of: the errorneous transformation is handling XML files without namespace, while the successful transformations acts on XML files with a target namespace.
I'm running Saxon EE 10.3 with Java 1.8 on Windows 10.
Replies (4)
Please register to reply
RE: Validation errors regarding XSLT (!) during XML transformation - Added by Michael Kay over 3 years ago
You haven't told us what's on line 2928 column 18 of xml-cc.xslt but my guess is it's a call on document('')
with a zero-length string as argument. The stack trace shows you're calling the document() function, and the errors report a problem with the stylesheet, so my guess is the stylesheet is reading its own source code.
I would also guess that you have turned on DTD validation (rather than schema validation), because the error messages are consistent with the XML parser trying to find a DTD for the document being read using document(), and failing to find one.
RE: Validation errors regarding XSLT (!) during XML transformation - Added by Franz Fackelmann over 3 years ago
Line 2928 column 18 is simply the end of the stylesheet - no document() there.
But there was indeed a document('')
somewhere in the code. Actually the full statement was base-uri(document(''))
- I assume, some wanted to log the URI of the stylesheet itself. I understand that an empty string "" would fail strict XML validation, but how come that the statement document('')
triggers parsing of the stylesheet itself?
Thank's for the valuable insight and in first case for pointing me into the right direction :-)
RE: Validation errors regarding XSLT (!) during XML transformation - Added by Franz Fackelmann over 3 years ago
Oh, I understood it myself (hope so)! The empty string in document('')
is of course an empty relative URI and is based on the stylesheet, so the statement parses the stylesheet.
RE: Validation errors regarding XSLT (!) during XML transformation - Added by Michael Kay over 3 years ago
The reason that document('') triggers parsing of the stylesheet is because by the time the stylesheet executes, its original source code is no longer available. Also, it is parsed differently when treated as a source document -- whitespace, comments, and processing instructions are all handled differently; what's more, if there are xml:base
attributes in the stylesheet then document('') might actually be parsing a completely different document.
The call on base-uri(document(''))
should almost certainly be replaced by a call on static-base-uri()
.
Please register to reply