Schematron xpath fail only once

Questions about XML that are not covered by the other forums should go here.
madhukar
Posts: 3
Joined: Fri Jul 24, 2020 3:34 pm

Schematron xpath fail only once

Post by madhukar »

Hello,

How to stop schematron to break the loop if the context fails the first time.

How to avoid looping the context across the xml so restrict displaying same error message multiple times(as we know if one fails rest will follow).

Thanks
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Schematron xpath fail only once

Post by tavy »

Hello,

I don't know exactly your use case, maybe you can give me an example of an XML document and a Schematron rule, to understand better the situation.
I think you can add the rule on a parent context, and then change the assert to fail if one of the rules is not true.

Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
madhukar
Posts: 3
Joined: Fri Jul 24, 2020 3:34 pm

Re: Schematron xpath fail only once

Post by madhukar »

Hello,

Below is the example posted

<xml>
<topic id="1">
<test>10</test>
</topic>
<topic id="2">
<test>10</test>
</topic>
<topic id="3">
<test>10</test>
</topic>
</xml>

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern>
<rule context="//topic/test">
<assert test=". > 5">
Value greater than 5
</assert>
</rule>
</pattern>
</schema>

Since the context will be looped thrice and will fail all the three times, can we stop looping through the entire xml if it fails the first time.

Hope this example helps to understand the context

Thanks
tavy
Posts: 364
Joined: Thu Jul 01, 2004 12:29 pm

Re: Schematron xpath fail only once

Post by tavy »

Hello,

I think the schema should be something like this:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
    <pattern>
        <rule context="xml">
            <let name="test" value="topic/test[number(text()) > 5]"/>
            <report test="$test" subject="$test[1]">
                Value greater than 5
            </report>
        </rule>
    </pattern>
</schema
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply