phax / ph-schematron

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

V8 #165

Closed phax closed 6 months ago

phax commented 7 months ago
phax commented 7 months ago

@bertrand-lorentz I did some further changes and cleansing - all the tests are still passing so I am confident that it is okay. The most relevant change was to use the "LetVariableResolver" only inside the bound Schematron to make sure it is always there. This simplifies the code and avoid dealing with the issue of it not being present.

If you don't have any objections, I would merge this to main and start a release build.

bertrand-lorentz commented 7 months ago

The change on the resolver looks good. Thanks for cleaning up ! 😄

I did notice an exception while running the unit test (although the test is not considered as failure):

[INFO] Running com.helger.schematron.pure.bound.xpath.PSXPathBoundSchemaTest
. . .
3883 [main] ERROR com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler - [error] [PSRule] @ external/test-sch/CellarBook.sch Failed to evaluate XPath expression to a boolean: '$nbBottles < 10' (net.sf.saxon.trans.XPathException: Cannot compare xs:string to xs:integer)
; SystemID: ; Line#: 1; Column#: 1
net.sf.saxon.trans.XPathException: Cannot compare xs:string to xs:integer
    at net.sf.saxon.expr.ValueComparison.compare(ValueComparison.java:397)
    at net.sf.saxon.expr.GeneralComparison.compare(GeneralComparison.java:694)
    at net.sf.saxon.expr.GeneralComparison$GeneralComparisonElaborator.evaluateManyToOne(GeneralComparison.java:903)
    at net.sf.saxon.expr.GeneralComparison$GeneralComparisonElaborator.lambda$elaborateForBoolean$1(GeneralComparison.java:839)
    at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:182)
    at com.helger.schematron.pure.xpath.XPathEvaluationHelper.evaluate(XPathEvaluationHelper.java:65)
    at com.helger.schematron.pure.xpath.XPathEvaluationHelper.evaluateAsBooleanObj(XPathEvaluationHelper.java:74)
    at com.helger.schematron.pure.xpath.XPathEvaluationHelper.evaluateAsBoolean(XPathEvaluationHelper.java:81)
    at com.helger.schematron.pure.bound.xpath.PSXPathBoundSchema._validateSerial(PSXPathBoundSchema.java:887)

I think it's because in PSXPathBoundSchema._evaluateVariables evaluateAsString is tried before evaluateAsNumber: an XPath expression that returns a number, like sum(wine/quantity), will not cause an exception when be evaluated as a string. But it then fails when the variable is used in an expression that expects a number.

I had put evaluateAsNumber before evaluateAsString to avoid this. This was just the result of trial and error, I'm not sure what the correct order is.

Note: you don't need to rush out a release for my account. It will anyways take a while before we can make use of it in our application.

phax commented 6 months ago

I changed the order to

  1. number
  2. boolean
  3. string to fix the exception - seems to be okay now. Added some more test cases to make sure no other exception occurs