Closed fviolette closed 7 years ago
When using pure mode, this is correctly handled. When the XSLT based version is used, it basically hangs with the error message "A variable reference is not allowed in an XSLT pattern".
I think this is related to https://github.com/Schematron/schematron/issues/6 - right?
As a workaround, I could suggest to first manually pre-process the pattern with the "pure" component.
This leads to the following Schematron:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern id="requiredAttribute">
<rule context="Customer">
<assert test="string-length(@type) > 0">
The <name /> element should have a
<value-of select="@type/name()" /> attribute.
</assert>
</rule>
</pattern>
</schema>
and when applied with XSLT the output is:
<?xml version="1.0" encoding="UTF-8"?>
<schematron-output xmlns="http://purl.oclc.org/dsdl/svrl" title="" schemaVersion="">
<active-pattern id="requiredAttribute" name="requiredAttribute" document=""></active-pattern>
<fired-rule context="Customer"></fired-rule>
<fired-rule context="Customer"></fired-rule>
<failed-assert location="/file[1]/Customer[2]" test="string-length(@type) > 0">
<text>
The Customer element should have a
attribute.
</text>
</failed-assert>
</schematron-output>
Duly noted.
As you are working with ANT I suggest I add a new "SchematronPreprocess" task that takes a file and writes a file? Or is this stupid?
It's not. I am still struggling with some of my content though so maybe some other +1 would be useful. If you feel like going ahead, I am not going to say no :-)
Here you go - any feedback is welcome :)
First attempt with above samples:
BUILD FAILED
C:\test\validate.xml:58: com.helger.schematron.
pure.exchange.SchematronReadException: C:\test\
topic.sch: Failed to resolve includes in resource [file=C:\test\topic.sch]
at com.helger.schematron.pure.exchange.PSReader.readSchema(PSReader.java
:1196)
at com.helger.schematron.ant.SchematronPreprocess.execute(SchematronPrep
rocess.java:142)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
Can you elaborate on the inckude please. I cant find it in above samples. Thx
Me neither :-| Update: Case closed, the issue is fixed on my side.
I pointed to a file which didn't exist - plain and simple. So, maybe we can make the log clearer about that.
It does work and I can easily chain it to the previous build. Is there anything else you would like to test, precisely?
On inspecting the preprocessed file, it tells me about the following error for <sqf:*>
elements, which is normal I guess since the namespace declarations are gone:
cvc-complex-type.3.2.2: Attribute 'fix' is not allowed to appear in element 'assert'.
--
cvc-complex-type.3.2.2: Attribute 'fix' is not allowed to appear in element 'report'
--
In my case, I would not object to fix
being removed from the preprocessed file.
Authors benefit from the live Schematron validation setup in the editor, and now with ph-schematron, we will run the validation on our full documentation set once in a while and possibly fully integrate this to our build pipeline with org.doctales.schematron after #50 and some more curation of the DITA content. So, except for the first case, fixes are not needed.
I think <sqf:fix>
must not be used in a <report>
or <assert>
. This is what the error message says or not?
<sch:pattern>
<sch:rule>
<sch:report test=""/>
<!-- should go after <report>/<assert> -->
<sqf:fix id=""/>
</sch:rule>
</sch:pattern>
Of course. I meant the @sqf:fix
reference in the first line, which gets preprocessed.
There is no error message as per ph-schematron but in the preprocessed file (so far that does not impair my progression with the testing but we could give it a thought).
This sample...
<sch:assert test="prodinfo/prodname" role="fatal" sqf:fix="insert-prodname">
The prodname element is mandatory.
</sch:assert>
<sqf:fix id="insert-prodname" role="add">
<sqf:description>
<sqf:title>Insert missing prodname element</sqf:title>
</sqf:description>
<sqf:add node-type="element" match="prodinfo" target="prodname" position="first-child"/>
</sqf:fix>
...is preprocessed:
<assert test="prodinfo/prodname" role="fatal" fix="insert-prodname">
The prodname element is mandatory.
</assert>
(Assert => error in the output preprocessed file: cvc-complex-type.3.2.2: Attribute 'fix' is not allowed to appear in element 'assert'
).
<ns0:fix xmlns:ns0="http://www.schematron-quickfix.com/validator/process" id="insert-prodname" role="add">
<ns0:description>
<ns0:title>Insert missing prodname element</ns0:title>
</ns0:description>
<ns0:add node-type="element" match="prodinfo" target="prodname" position="first-child" />
</ns0:fix>
(Fix => warning in the output preprocessed file: The ns0:fix element is not used by an assert or a report inside of this rule
).
The foreign elements are "optimized" away. I opened issue #51 for this.
In your case, did you add the <sch:ns ...>
element to your Schematron?
Yes, indeed.
I assume this can be closed, as #51 is what is left. Any objections?
None. Thanks again!
Hello,
A couple of issues with abstract patterns and
schematronProcessingEngine="schematron"
.The lib is working for me but I currently have many patterns and rules written in the way detailed below.
Versions tested:
ph-schematron-ant-task-4.3.4-jar-with-dependencies.jar
ph-schematron-ant-task-5.0.0-20170807.123330-8-jar-with-dependencies.jar
Example from the ISO Schematron spec repurposed a bit.
schematron.sch
topic.xml
Log