Algorithmic Constraint Checking

Roger Costello

Click arrow key () to navigate to next page

Example: Checking Election Results

  1. <xml version="1.0"?>
  2. <ElectionResultsByPercentage>
  3. <Candidate name="John">61</Candidate>
  4. <Candidate name="Sara">24</Candidate>
  5. <Candidate name="Bill">15</Candidate>
  6. </ElectionResultsByPercentage>

Different Type of Checking

Rule

  1. <sch:rule context="ElectionResultsByPercentage">
  2. <sch:assert test="sum(Candidate) = 100">
  3. The sum of the election results must be 100
  4. </sch:assert>
  5. </sch:rule>

Pattern

  1. <sch:pattern name="Vote Count">
  2. <sch:p>The election results must add up to 100%.</sch:p>
  3. <sch:rule context="ElectionResultsByPercentage">...</sch:rule>
  4. </sch:pattern>

Schematron Schema

  1. <xml version="1.0"?>
  2. <sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
  3. <sch:pattern name="Vote Count">
  4. <sch:p>The election results must add up to 100%.</sch:p>
  5. <sch:rule context="ElectionResultsByPercentage">
  6. <sch:assert test="sum(Candidate) = 100">
  7. The sum of the election results must be 100
  8. </sch:assert>
  9. </sch:rule>
  10. </sch:pattern>
  11. </sch:schema>

Validate

Example: Checksum Validation

  1. <xml version="1.0"?>
  2. <Election>
  3. <ResultsByPercentage>
  4. <Candidate name="John">61</Candidate>
  5. <Candidate name="Sara">24</Candidate>
  6. <Candidate name="Bill">15</Candidate>
  7. </ResultsByPercentage>
  8. <DocumentNumber>4389023232</DocumentNumber>
  9. </Election>

Checksum

  1. <sch:pattern name="Checksum">
  2. <sch:rule context="DocumentNumber">
  3. <sch:assert test="(
  4. (substring(.,1,1) * 1) +
  5. (substring(.,2,1) * 2) +
  6. (substring(.,3,1) * 3) +
  7. (substring(.,4,1) * 4) +
  8. (substring(.,5,1) * 5) +
  9. (substring(.,6,1) * 6) +
  10. (substring(.,7,1) * 7) +
  11. (substring(.,8,1) * 8) +
  12. (substring(.,9,1) * 9)
  13. ) mod 9 = substring(.,10,1)">
  14. The checksum (i.e. the tenth digit) must equal the sum of the preceding nine digits multiplied by their position, mod 9.
  15. </sch:assert>
  16. </sch:rule>
  17. </sch:pattern>

Validate

Another Checksum Example

Lab 3

Homepage