phax / ph-schematron

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

Failed to precompile the supplied schema. #135

Closed apostaat closed 2 years ago

apostaat commented 2 years ago

Given:

I tried to investigate passing CollectingPSErrorHandler to .bind method and literally all of the errors stem from calling an external voc.xml file in schematron assertion.

Part of custom error report I have in YAML format:

fieldname: PSAssertReport [ID=a-1098-7497]
level-of-error: ERROR
error-field: PSAssertReport [ID=a-1098-7497]
verbose-explanation: >-
  [Text=Failed to compile XPath expression in <assert>: '@moodCode and
  @moodCode=document('voc.xml')/voc:systems/voc:system[@valueSetOid='2.16.840.1.113883.11.20.9.18']/voc:code/@value'
  with the following variables: {}]

Corresponding part of schematron file, that causes error:

<sch:assert id="a-1098-7497" test="@moodCode and @moodCode=document('voc.xml')/voc:systems/voc:system[@valueSetOid='2.16.840.1.113883.11.20.9.18']/voc:code/@value">SHALL contain exactly one [1..1] @moodCode, which SHALL be selected from ValueSet MoodCodeEvnInt urn:oid:2.16.840.1.113883.11.20.9.18 STATIC 2011-04-03 (CONF:1098-7497).</sch:assert>

Corresponding part of voc.xml:

<system valueSetOid="2.16.840.1.113883.11.20.9.18" valueSetName="MoodCodeEvnInt">
    <code value="EVN" displayName="event (occurrence)" codeSystemName="HL7ActMood" codeSystem="2.16.840.1.113883.5.1001" />
    <code value="INT" displayName="intent" codeSystemName="HL7ActMood" codeSystem="2.16.840.1.113883.5.1001" />
  </system>

voc.xml is in the same directory as schematron file, so I do not think that mere absence of the file causes such behaviour.

My hypothesis is that additional xml file (voc.xml) is not properly resolved, but I have not found which mechanisms provide such functionality.

P.S.: I have thoroughly readed similar issues, but unfortunately I have not found a solution:

phax commented 2 years ago

@apostaat I think the problem is, that you are using the document function. Unfortunately the document function is an XSLT function and not an XPath function, so you cannot use it with the "pure" implementation. You need to switch to the XSLT based version - sorry.

apostaat commented 2 years ago

@phax Thank you for an answer.