Schematron: Test that a string matches an ID from a list of available IDs
Posted: Fri Jul 26, 2019 1:03 am
I have an XML file that contains a list of possible question answers as well as the correct answer. I want to use schematron to verify that the correct answer value (a string) exists in the list of possible answer IDs.
I'm comparing the string value to the list IDs, but am coming up short.
XML:
Schematron rule:
However, all 3 <a class="answer-ref">s trigger the error when only the first one should (with value i1555 - actual value should be i155).
I'm comparing the string value to the list IDs, but am coming up short.
XML:
Code: Select all
<question>
<div class="answer" id="i149">
<div class="choice" id="i152">
<div class="list" id="i154">
<ol>
<li id="i155">Red</li>
<li id="i156">Blue</li>
<li id="i157">Green</li>
<li id="i158">Yellow</li>
</ol>
</div>
</div>
</div>
<div class="response-processing" id="i159">
<div class="condition" id="i161">
<div class="correct" id="i162">
<div class="response" id="i163">
<p>
<a class="answer-ref" href="#i152" id="i164">i1555</a>
</p>
<p>
<a class="answer-ref" href="#i152" id="i165">i156</a>
</p>
<p>
<a class="answer-ref" href="#i152" id="i166">i157</a>
</p>
</div>
</div>
</div>
</div>
</question>
Code: Select all
<pattern id="answerIDnotLocal">
<let name="answer" value="ancestor::question/div[@class='answer']/div[@class='choice']/div[@class='list']/ol//li/@id"/>
<rule context="a[@class='answer-ref']">
<assert test=". = $answer">This <value-of select="."/> doesn't match an available answer id.</assert>
</rule>
</pattern>