Implementing schematron rules -


i new schematron , have following problem. snippet xhtml file:

<div class="provision">   <!-- provision (section) -->   <header>     <!-- headers -->     <div class="desig">       <!-- if provision header/div@class=desig/span@class=num required -->       <span class="num">1.</span>     </div>     <h1 class="title">prov-title</h1>   </header>   <p class="prov">para-prov-level</p>   <p class="prov">para-prov-level</p>   <div class="glossary">     <!-- glossary -->     <!-- glossary requires dl -->     <dl>       <!-- dl should have dt, , @ least 1 dd -->       <dt> term </dt>       <dd>definition</dd>       <dt> term </dt>       <dd>definition</dd>     </dl>   </div>   <div class="level-1-grp">     <!-- subsection -->     <header>       <div class="desig">         <span class="num">(1)</span>       </div>     </header>     <p class="level-1">para-level-1</p>     <div class="level-2-grp">       <header>         <div class="desig">           <span class="num">(a)</span>         </div>       </header>       <p class="level-2">para-level-2</p>     </div>     <div class="level-2-grp">       <header>         <div class="desig">           <span class="num">(b)</span>         </div>       </header>       <p class="level-2">para-level-2</p>     </div>     <p class="level-1">para-level-1</p>   </div>   <p class="prov">para-prov-level</p> </div> 

and create rule check if there provision header/div@class=desig/span@class=num required , glossary requires dl. have been trying not work:

<iso:pattern id="structure-provision">   <iso:title>testing provision structure...</iso:title>   <iso:rule context="*:div[@class='provision']">     <iso:assert test="self::*:header/div[@class ='desig']/*:span[@class='num']">if provision header/div@class=desig/span@class=num required</iso:assert>   </iso:rule> </iso:pattern>  <!--glossory structure -->  <iso:pattern id="structure-glossory">   <iso:title>testing provision structure...</iso:title>   <iso:rule context="*:div[@class='glossory']">     <iso:assert test="self::*:dl">glossary requires dl</iso:assert>     <iso:assert test="self::*:dl/dt">dl should have dt</iso:assert>   </iso:rule>  </iso:pattern> 

any appreciated. thanks

you missing namespace on div element in first iso:assert.

the english language not precise, interpreted requirements in 2 ways.

1) if there provision (header/div@class=desig/span@class=num required , glossary requires dl). "if x, , b". if case, single pattern should used.

<?xml version="1.0" encoding="utf-8"?> <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" querybinding="xslt2">     <sch:pattern id="structure-provision">         <sch:title>provisioning structure</sch:title>         <sch:rule context="*:div[@class='provision']">             <sch:assert test="*:header/*:div[@class ='desig']/*:span[@class='num']">                 provision structure requires header/div@class=desig/span@class=num             </sch:assert>             <sch:assert test="*:div[@class='glossary']/*:dl">                 glossary requires dl             </sch:assert>         </sch:rule>     </sch:pattern> </sch:schema> 

2) (if there provision header/div@class=desig/span@class=num required) , (glossary requires dl). "if x, a. also, if y, b." if case, 2 patterns should used.

<?xml version="1.0" encoding="utf-8"?> <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" querybinding="xslt2">     <sch:pattern id="provision-structure">         <sch:title>provisioning structure</sch:title>         <sch:rule context="*:div[@class='provision']">             <sch:assert test="*:header/*:div[@class ='desig']/*:span[@class='num']">                 provision structure requires header/div@class=desig/span@class=num             </sch:assert>         </sch:rule>     </sch:pattern>      <sch:pattern id="glossary-structure">         <sch:title>provisioning structure</sch:title>         <sch:rule context="*:div[@class='glossary']">             <sch:assert test="*:dl">                 glossary requires dl             </sch:assert>             <sch:assert test="*:dl/*:dt">                 dl requires dt             </sch:assert>         </sch:rule>     </sch:pattern> </sch:schema> 

i recommend splitting requirements several rules/patterns make things more robust , organized. example, have of rules related provisioning structure within single pattern. if glossary rules should enforced regardless of whether glossary within provisioning structure, glossary should have own pattern.

also, define , use namespace elements , use within schematron rules. assume xhtml or similar? xpath expressions become like:

<sch:rule context="xhtml:div[@class='provision']">     <sch:assert test="xhtml:header/xhtml:div[@class ='desig']/xhtml:span[@class='num']">         rule text here     </sch:assert> </sch:rule> 

Comments