Page 1 of 1

Quick fix fails silently

Posted: Tue Jul 09, 2019 10:43 pm
by bburns
I have a schematron rule that checks for the substring 911 in various contexts. I want to replace the string with an empty element that will be used to automatically generate the emergency number for each locale. The initial test works, but the quick fix does not. I get no error, but nothing happens.

<rule context="title | navtitle | p | dt | dd | li | cmd" role="info">
<report test="contains(., '911')" role="warn" sqf:fix="replace911text">All 911 text should be replaced with emnumber.</report>
<sqf:fix id="replace911text">
<sqf:description>
<sqf:title>Replace text 911 with the emnumber tag.</sqf:title>
</sqf:description>
<sqf:stringReplace regex="911">
<emnumber/>
</sqf:stringReplace>
</sqf:fix>
</rule>

My fix is almost identical to one shown at https://td-demo.titaniasoftware.com/por ... operations, which I assume works.

Any suggestions?

Thanks,
Bill

Re: Quick fix fails silently

Posted: Wed Jul 10, 2019 9:32 am
by tavy
Hi Bill,

The sqf:stringReplace operation applies only on text nodes. The context of your rule are element nodes (title | navtitle | p | dt | dd | li | cmd), and this is why the quick fix does not work. Therefore, you need to specify that the quick fix will match the text from the current element using match="text()". Also I recommend to use a prefix for the Schematron elements otherwise the <emnumber/> element will be considered to be in the Schematron namespace, and you want to be in no namespace. The Schematron should look something like this:

Code: Select all

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
    xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
    <sch:pattern>
        <sch:rule context="title | navtitle | p | dt | dd | li | cmd" role="info">
            <sch:report test="contains(., '911')" role="warn" sqf:fix="replace911text">All 911 text should be replaced with emnumber.</sch:report>
            <sqf:fix id="replace911text">
                <sqf:description>
                    <sqf:title>Replace text 911 with the emnumber tag.</sqf:title>
                </sqf:description>
                <sqf:stringReplace match="text()" regex="911">
                    <emnumber/>
                </sqf:stringReplace>
            </sqf:fix>
        </sch:rule>
    </sch:pattern>
</sch:schema>
Probably we should show an error in case the quick fix does not work, and explain what happen. I will add an issue on our internal issue tracker for this. Thanks for your feedback.

You can read more about the SQF stringReplace operation in our User manual:
https://www.oxygenxml.com/doc/versions/ ... ng-replace

Best Regards,
Octavian

Re: Quick fix fails silently

Posted: Thu Jul 11, 2019 4:58 pm
by bburns
Thanks, Octavian. That worked. Still finding my way around some of the functions. I tried using matches() in the report node test as in the example, and that didn't work, so I didn't think to use it once I'd matched the substring.

Re: Quick fix fails silently

Posted: Mon Jul 15, 2019 6:40 pm
by bburns
Incidently, can these quick fixes be run automatically outside of the Oxygen environment? I haven't seen their use anywhere else.

Re: Quick fix fails silently

Posted: Tue Jul 16, 2019 3:51 pm
by tavy
Hi Bill,

The quick fixes can be run only inside Oxygen, we so not have support to run them outside.
You can try to use Escali engine, that also supports Schematron Quick Fixes:
https://github.com/schematron-quickfix/escali-package

Best Regards,
Octavian