phax / ph-schematron

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

Rule not fired when context is an attribute #123

Closed Falcon2677 closed 2 years ago

Falcon2677 commented 2 years ago

When using ph-schematron-xslt-6.2.5.jar with schematron rule using a context with an attribute and SchematronResourceSCH, rule is not fired.

I need to use SchematronResourceSCH and not SchematronResourcePure due to others rules not taken in charge in Pure.

It appears that the problem is link to the variable definition of context-path in file 20100710-xslt2/iso_schematron_skeleton_for_saxon.xsl.

When replacing:

         <xsl:if test="$attributes='true' and parent::node() ">@*|</xsl:if>

with

         <xsl:if test="$attributes='true'">@*|</xsl:if>

Rule using attribute in context is correctly fire.

See Files.zip which contains a sample of xml file and sch file.

phax commented 2 years ago

Existing SVRL output:

<?xml version="1.0" encoding="UTF-8"?>
<ns2:schematron-output xmlns:ns2="http://purl.oclc.org/dsdl/svrl" title="" schemaVersion="">
  <ns2:ns-prefix-in-attribute-values prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance" />
  <ns2:ns-prefix-in-attribute-values prefix="message" uri="msg:ns" />
  <ns2:active-pattern document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\issues\github123\Data.xml" />
  <ns2:fired-rule context="//*[resolve-QName(@xsi:type,.)=QName('msg:line','Type')]/idType" />
  <ns2:fired-rule context="//*[resolve-QName(@xsi:type,.)=QName('msg:line','Type')]/idType" />
  <ns2:failed-assert location="/*[local-name()='Data']/body/content/objects/object[2]/idType" test="matches(.,'^1')">
    <ns2:text>Rule on node idType value must start with 1</ns2:text>
      <ns2:diagnostic-reference diagnostic="R2-en" xml:lang="en">
Rule on node idType value must start with 1</ns2:diagnostic-reference>
  </ns2:failed-assert>
</ns2:schematron-output>

with your modification it becomes:

<?xml version="1.0" encoding="UTF-8"?>
<ns2:schematron-output xmlns:ns2="http://purl.oclc.org/dsdl/svrl" title="" schemaVersion="">
  <ns2:ns-prefix-in-attribute-values prefix="xsi" uri="http://www.w3.org/2001/XMLSchema-instance" />
  <ns2:ns-prefix-in-attribute-values prefix="message" uri="msg:ns" />
  <ns2:active-pattern document="C:\dev\git\ph-schematron\ph-schematron-xslt\src\test\resources\issues\github123\Data.xml" />
  <ns2:fired-rule context="//*[resolve-QName(@xsi:type,.)=QName('msg:line','Type')]/@id" />
  <ns2:fired-rule context="//*[resolve-QName(@xsi:type,.)=QName('msg:line','Type')]/idType" />
  <ns2:fired-rule context="//*[resolve-QName(@xsi:type,.)=QName('msg:line','Type')]/@id" />
  <ns2:failed-assert location="2345" test="matches(.,'^1')">
    <ns2:text>Rule on id attribute value must start with 1</ns2:text>
      <ns2:diagnostic-reference diagnostic="R1-en" xml:lang="en">
Rule on id attribute value must start with 1</ns2:diagnostic-reference>
  </ns2:failed-assert>
  <ns2:fired-rule context="//*[resolve-QName(@xsi:type,.)=QName('msg:line','Type')]/idType" />
  <ns2:failed-assert location="/*[local-name()='Data']/body/content/objects/object[2]/idType" test="matches(.,'^1')">
    <ns2:text>Rule on node idType value must start with 1</ns2:text>
      <ns2:diagnostic-reference diagnostic="R2-en" xml:lang="en">
Rule on node idType value must start with 1</ns2:diagnostic-reference>
  </ns2:failed-assert>
</ns2:schematron-output>

Which is I think a good thing. I just can't image what the implications are.... I will leave it in an see :)

Falcon2677 commented 2 years ago

Great, you are very reactive 😄 .

When do you planned to release a 6.2.6 ?

phax commented 2 years ago

Work in progress :)

phax commented 2 years ago

Should be on Maven Central in the next few minutes