phax / ph-schematron

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

Validation with absolute path in xslt function #60

Closed staskable closed 3 years ago

staskable commented 6 years ago

Hi, I m using Pure validation but I have an error when I try to validate

    _<assert test="
            (doc(resolve-uri(concat('$path','/','DIZ/XML_PAI_V2/2.16.840.1.113883.2.9.2.30.3.1.3.13.6.4.xml')))//el[@code=$VAL])"

            >Error: L'elemento <name/> non è presente nel dizionario specifico
    </assert>_

The error is

_07-Nov-2017 07:28:08.870 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 8427 ms 12616 [http-nio-8093-exec-1] ERROR com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler - PSRule - Failed to evaluate XPath expression to a boolean: 'doc(resolve-uri(concat('file:///Users/quest982/testCDA','/',concat('DIZ/XML_PAI_V2/',hl7:code/@codeSystem,'.xml'))))//el[@code=hl7:code/@code]' ; SystemID: ; Line#: 1; Column#: 24 net.sf.saxon.trans.XPathException: I/O error reported by XML parser processing file:///Users/quest982/testCDA/DIZ/XML_PAI_V2/2.16.840.1.113883.6.73.xml: /Users/quest982/testCDA/DIZ/XML_PAIV2/2.16.840.1.113883.6.73.xml (No such file or directory)

The file exists for sure, I think the error is due for the empty value of SystemId. Is there a way to set up SystemId? Or have you got an equivalent solution?

Thanks a lot

mathiasghys commented 6 years ago

I managed to solve this issue by setting my self defined URIResolver: https://stackoverflow.com/questions/47226063/resolving-relative-paths-when-using-ph-schematron Hope it can help you.

phax commented 6 years ago

The problem here is identical: you are using the XSLT doc function so you CANNOT use the Pure implementation (as it is XPath only). So instead you need to switch to the SchematronResourceSCH" (if you have the .sch file and need to convert it to XSLT first) orSchemtronResourceXSLT` (if you already have the pre-compiled Schematron-XSLT - e.g. created by the contained Maven plugin).

Setting a custom URI resolver may help here! Thanks Mathias for linking SO, GitHub and Email together :)))

jkiddo commented 4 years ago

I succeeded using Pure by adding the following to the https://github.com/phax/ph-commons/blob/d4c95abb942185972cfef0484014acdc9edb90e7/ph-xml/src/main/java/com/helger/xml/xpath/XPathHelper.java

    try
    {
      // First try to use Saxon, using the context class loader
      aXPathFactory = XPathFactory.newInstance (XPathFactory.DEFAULT_OBJECT_MODEL_URI,
              "net.sf.saxon.xpath.XPathFactoryImpl",
              ClassLoaderHelper.getContextClassLoader ());

//my contribution
      XPathFactoryImpl saxonFactory = (XPathFactoryImpl) aXPathFactory;
      saxonFactory.getConfiguration().setURIResolver(new AwesomeClasspathResourceURIResolver());

    }
phax commented 4 years ago

will check it after my vacation. This is Saxon specific but who cares ;)

stale[bot] commented 4 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

The official solution to this, would be (to my understanding) as follows: