Validating the DITA schema from Schematron

Post here questions and problems related to editing and publishing DITA content.
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Validating the DITA schema from Schematron

Post by chrispitude »

Hi all,

We want our writers to use RelaxNG schemas, not DTD schemas. I recently asked Octavian how I could enforce this in Schematron.

My original thinking was to try to search from the <!DOCTYPE ...> declaration from Schematron. However, Octavian suggested a solution that instead reports when the <?xml-model ...> RelaxNG schema declaration is missing:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
    xmlns:sqf="http://www.schematron-quickfix.com/validator/process" xmlns:saxon="http://saxon.sf.net/">
    <sch:let name="rngDeclaration" value="processing-instruction('xml-model')
        [saxon:get-pseudo-attribute('schematypens')='http://relaxng.org/ns/structure/1.0']"/>
    <sch:pattern>
        <sch:rule context="/element()">
            <sch:assert test="exists($rngDeclaration)">DTD schemas are unsupported in our flow; use a RelaxNG schema instead.</sch:assert>
        </sch:rule>
    </sch:pattern>
</sch:schema>
Note that he uses some kind of Saxon function call to get the xml-model PI. The rule applies to the document root element ("/element()").

I would have never figured this out myself, and I wanted to share it here in case it was useful to others!