Digital humanities


Maintained by: David J. Birnbaum (djbpitt@gmail.com) [Creative Commons BY-NC-SA 3.0 Unported License] Last modified: 2022-04-03T18:22:24+0000


Test #6: Schematron

The data

The data for the Schematron test is the Shakespearean sonnets file that you worked with previously, which is located at http://dh.obdurodon.org/shakespeare-sonnets.xml.

The tasks

Create a Schematron schema to validate two features of the sonnets file: 1) Does the Roman numeral match the position of the sonnet? and 2) Does every sonnet have exactly 14 lines?

Our solution

One solution is:



    
        Validate Shakespearean sonnets file
        
            Create convenience variables
            
            
            
            
            Report line count other than 14 as a warning
            Sonnet # has 
                lines
            Report incorrect Roman numeral as an error
            The sonnet with
                Roman numeral  is in offset position
                    
        
    

]]>

We begin (lines 8–11) by declaring variables that serve two purposes. First, we use some of the values more than once, and by computing them once and binding them to variables, we avoid having to repeat the computation. Second, we find our @test attributes easier to read if we write them with variables instead of putting all of the computation directly inside the @test attribute value.

The two validation operations (<sch:assert> elements) compare values and report a warning for a line count other than 14 and an error for an incorrect Roman numeral. We use variables in our reporting to provide specific information about the nature of the issue.

We use <sch:title> and <sch:p> elements for documentation. There’s nothing wrong with using regular XML comments instead, but if you open the Schematron file in <oXygen/> and click on the button labeled Author at the bottom of the editor panel, you’ll see that <oXygen/> knows how to format those special Schematron documentation elements in a human-friendly way. (You can return from the Author view to the regular <oXygen/> editing view by clicking on the Text button below the editor panel.)