phax / ph-schematron

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

Schematron http://docbook.org/xml/5.1CR4/sch/docbook.sch #96

Closed aanno closed 4 years ago

aanno commented 4 years ago

When I use http://docbook.org/xml/5.1CR4/sch/docbook.sch Schematron to validate a DocBook, I encounter the following error:

net.sf.saxon.trans.XPathException: Cannot find a 0-argument function named Q{http://www.w3.org/2005/xpath-functions}current(). External function calls have been disabled
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.grumble(XPathParser.java:315)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.grumble(XPathParser.java:286)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.reportMissingFunction(XPathParser.java:3436)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(XPathParser.java:3358)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2206)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:2076)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1995)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1957)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1971)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1824)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseBinaryExpression(XPathParser.java:823)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:753)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:660)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parsePredicate(XPathParser.java:2159)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parsePredicate(XPathParser.java:2115)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:2085)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseRemainingPath(XPathParser.java:2035)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1940)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1971)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1824)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:753)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseFunctionArgument(XPathParser.java:3552)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseFunctionCall(XPathParser.java:3322)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseBasicStep(XPathParser.java:2206)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseStepExpression(XPathParser.java:2076)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseRelativePath(XPathParser.java:1995)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parsePathExpression(XPathParser.java:1957)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseSimpleMappingExpression(XPathParser.java:1971)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseUnaryExpression(XPathParser.java:1824)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseExprSingle(XPathParser.java:753)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parseExpression(XPathParser.java:660)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.XPathParser.parse(XPathParser.java:522)
    at Saxon.HE@9.9.1-6/net.sf.saxon.expr.parser.ExpressionTool.make(ExpressionTool.java:107)
    at Saxon.HE@9.9.1-6/net.sf.saxon.xpath.XPathEvaluator.compile(XPathEvaluator.java:193)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema._compileXPath(PSXPathBoundSchema.java:104)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema._createBoundPatterns(PSXPathBoundSchema.java:291)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema.bind(PSXPathBoundSchema.java:472)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.binding.xpath.PSXPathQueryBinding.bind(PSXPathQueryBinding.java:150)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.bound.PSBoundSchemaCacheKey.createBoundSchema(PSBoundSchemaCacheKey.java:269)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.bound.PSBoundSchemaCache.lambda$new$7dce85cd$1(PSBoundSchemaCache.java:55)
    at com.helger.commons@9.3.8/com.helger.commons.cache.MappedCache.getFromCache(MappedCache.java:337)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.SchematronResourcePure.createBoundSchema(SchematronResourcePure.java:284)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.SchematronResourcePure.getOrCreateBoundSchema(SchematronResourcePure.java:298)
    at com.helger.schematron@5.4.0/com.helger.schematron.pure.SchematronResourcePure.isValidSchematron(SchematronResourcePure.java:316)
    at com.github.aanno.dbtoolchain/com.github.aanno.dbtoolchain.xml.XmlSingleton.getSchematronResource(XmlSingleton.java:57)
    at com.github.aanno.dbtoolchain/com.github.aanno.dbtoolchain.DbValidation.main(DbValidation.java:51)

I guess this is because I'm using Saxon.HE@9.9.1-6 and - according the feature matrix - the open source saxon does not support XPath functions.

Is there a way to tell ph-schematron which implementation of javax.xml.xpath.XPathExpression to use?

aanno commented 4 years ago

When I use https://github.com/aanno/ph-schematron/tree/issue_96 in conjunction with -Djavax.xml.xpath.XPathFactory=com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl the issue is solved.

phax commented 4 years ago

Thanks. Sorry for the delay - I am currently busy with other issues. That looks like a classical issue between Saxon and Xalan 🤷‍♂

phax commented 4 years ago

I again reworked the API a bit to be more backwards compatible, but from a general point of view I didn't change the logic. Thanks for PR'ing this :)

EcoFreak commented 4 years ago

How did you manage to fix this issue? I'm using version 5.6 and I'm still encountering it.

Thanks !

phax commented 4 years ago

Did you see setting the XML factory via the system property:

-Djavax.xml.xpath.XPathFactory=com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl
EcoFreak commented 4 years ago

Yes but still no luck. I was using variables to simplify a Schematron rule but because I'm using SchematronResourcePure (and after found some issue related to the use of variables), I had to change and the alternative I found was to use current() function to get the context node inside a Xpath predicate.

Any thoughts?

phax commented 4 years ago

Please try the ...Xslt version instead of the ...Pure version. Pure only supports Xpath and basically sucks for anything real-world...

EcoFreak commented 4 years ago

I managed to get it working with SchematronResourceXSLT but using this approach I have to "compile" the schematron in advance which complicated due to many phases. I tried using SchematronResourceSCH thinking it would work as well (compiling the schematron to xlst and then use it to create the svrl) but it's just hangs for a long time. Is it possible to use SchematronResourceSCH or am I going at this the wrong way?

phax commented 4 years ago

Schematron Pure: works only with XPath rules - XSLT is not possible. Schematron XSLT: unleashes the full power of Schematron using XSLT as the language of choice

To simplify the process, I added the Maven plugin/ANT task to convert the SCH to XSLT at compile/build time. At runtime you can than simply use the XSLT which is much quicker in execution. hth