Schematron: Test that a string matches an ID from a list of available IDs
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 5
- Joined: Sat Mar 02, 2019 3:57 am
Schematron: Test that a string matches an ID from a list of available IDs
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>
-
- Posts: 9431
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Schematron: Test that a string matches an ID from a list of available IDs
Hi,
How about if you move the <let> expression one line down inside the <rule> element so that it's executed in the right context?
Regards,
Radu
How about if you move the <let> expression one line down inside the <rule> element so that it's executed in the right context?
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 5
- Joined: Sat Mar 02, 2019 3:57 am
Re: Schematron: Test that a string matches an ID from a list of available IDs
Regardless of the <let>, the answer ended up being the use of quantified expressions:
Code: Select all
<pattern id="answerIDnotLocal">
<rule context="question">
<let name="answer" value="div[@class='response-processing']/div[@class = 'condition']/div[@class = 'correct']"/>
<let name="choice" value="div[@class = 'answer']//div[@class = 'list']//li/@id"/>
<assert test="every $a in $answer satisfies $a = $choice">This question doesn't match an available answer id.</assert>
</rule>
</pattern>
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service