phax / ph-schematron

Java Schematron library that supports XSLT and native application
Apache License 2.0
115 stars 36 forks source link

More clues to where the error is located would be nice #52

Open jkiddo opened 7 years ago

jkiddo commented 7 years ago
[main] ERROR com.helger.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Unexpected token ")" at start of expression)
[main] ERROR com.helger.xml.transform.XMLTransformerFactory - Failed to parse javax.xml.transform.dom.DOMSource@383864d5
javax.xml.transform.TransformerConfigurationException: net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
    at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:157)
    at com.helger.xml.transform.XMLTransformerFactory.newTemplates(XMLTransformerFactory.java:263)
    at com.helger.schematron.xslt.SchematronProviderXSLTFromSCH.<init>(SchematronProviderXSLTFromSCH.java:220)
    at com.helger.schematron.xslt.SchematronResourceSCHCache.createSchematronXSLTProvider(SchematronResourceSCHCache.java:69)
    at com.helger.schematron.xslt.SchematronResourceSCHCache.getSchematronXSLTProvider(SchematronResourceSCHCache.java:145)
    at com.helger.schematron.xslt.SchematronResourceSCH.getXSLTProvider(SchematronResourceSCH.java:92)
    at com.helger.schematron.xslt.AbstractSchematronXSLTBasedResource.isValidSchematron(AbstractSchematronXSLTBasedResource.java:187)
    at com.helger.schematron.AbstractSchematronResource.applySchematronValidationToSVRL(AbstractSchematronResource.java:255)
    at cda.schematronvalidator.SchematronValidator.runValidation(SchematronValidator.java:143)
    at cda.schematronvalidator.SchematronValidator.validate(SchematronValidator.java:114)
    at cda.schematronvalidator.SchematronValidator.main(SchematronValidator.java:96)
Caused by: net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
    at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:746)
    at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:154)
    ... 10 more
Caused by: net.sf.saxon.trans.XPathException: Errors were reported during stylesheet compilation
    at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:259)
    at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:106)
    at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:743)
    ... 11 more
---------
net.sf.saxon.s9api.SaxonApiException: Errors were reported during stylesheet compilation
    at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:746)
    at net.sf.saxon.jaxp.SaxonTransformerFactory.newTemplates(SaxonTransformerFactory.java:154)
    at com.helger.xml.transform.XMLTransformerFactory.newTemplates(XMLTransformerFactory.java:263)
    at com.helger.schematron.xslt.SchematronProviderXSLTFromSCH.<init>(SchematronProviderXSLTFromSCH.java:220)
    at com.helger.schematron.xslt.SchematronResourceSCHCache.createSchematronXSLTProvider(SchematronResourceSCHCache.java:69)
    at com.helger.schematron.xslt.SchematronResourceSCHCache.getSchematronXSLTProvider(SchematronResourceSCHCache.java:145)
    at com.helger.schematron.xslt.SchematronResourceSCH.getXSLTProvider(SchematronResourceSCH.java:92)
    at com.helger.schematron.xslt.AbstractSchematronXSLTBasedResource.isValidSchematron(AbstractSchematronXSLTBasedResource.java:187)
    at com.helger.schematron.AbstractSchematronResource.applySchematronValidationToSVRL(AbstractSchematronResource.java:255)
    at cda.schematronvalidator.SchematronValidator.runValidation(SchematronValidator.java:143)
    at cda.schematronvalidator.SchematronValidator.validate(SchematronValidator.java:114)
    at cda.schematronvalidator.SchematronValidator.main(SchematronValidator.java:96)
Caused by: net.sf.saxon.trans.XPathException: Errors were reported during stylesheet compilation
    at net.sf.saxon.style.StylesheetModule.loadStylesheet(StylesheetModule.java:259)
    at net.sf.saxon.style.Compilation.compileSingletonPackage(Compilation.java:106)
    at net.sf.saxon.s9api.XsltCompiler.compile(XsltCompiler.java:743)
    ... 11 more
[main] WARN com.helger.schematron.xslt.SchematronResourceSCHCache - The Schematron resource 'schema.sch' is invalid!

If the name of the file in question could be part of the stacktrace or the failed expression could be part of the trace it would be great. (The file 'schema.sch' is only the container for a lot of other files).

phax commented 7 years ago

Currently on vacation so only a quick answer.please try v5.0.0-b1 and give me feedback please. Thx

jkiddo-dxc commented 7 years ago

Looks like the same to me using v5.0.0-b1

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

phax commented 3 years ago

I enabled a flag in the Saxon runtime - maybe the makes things a bit better.

BBE78 commented 1 year ago

Hi ! I'm also interested in this feature (ie at least line number) on errors. But I'm not sure to understand what we (ph-schematron users) should code to have this information?

I'm using the following code to collect schematron errors:

StreamSource source = new StreamSource(new StringInputStream(xml, StandardCharsets.UTF_8));
SchematronOutputType ouput = sch.applySchematronValidationToSVRL(source);
final ICommonsList<SVRLFailedAssert> failedAssertions = SVRLHelper.getAllFailedAssertions(ouput);

Could you please provide an explanation or code snippet on how to read the "location" information ? Thanks

phax commented 1 year ago

Hi, the problem with the line numbers is mainly for the internal conversion of SCH to XSLT.

In what exact context to do you expect line numbers?

In the created SVRL there is no option to get the line number of the respective XML - that's why you have the XPath expression.

Please elaborate a bit more - thx

BBE78 commented 1 year ago

Hi, here is what I want: I want the error lines number when I validate a XML content against a schematron. Maybe I'm not using the correct API to do this.

phax commented 1 year ago

Unfortunately SVRL, the output language for Schematron validation, does not foresee the provision of line and column numbers for matching elements. So unfortunately there is no standard way to provide this - sorry

BBE78 commented 1 year ago

Do we have another ways to have these line/column information ?

phax commented 1 year ago

Well I am not aware of a simple solution to do it. Evtl. you can use this method with some value-of assertion elements, but I never used it...