Validating the DITA schema from Schematron

Post here questions and problems related to editing and publishing DITA content.
Posts: 585
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="" queryBinding="xslt2"
    xmlns:sqf="" xmlns:saxon="">
    <sch:let name="rngDeclaration" value="processing-instruction('xml-model')
        <sch:rule context="/element()">
            <sch:assert test="exists($rngDeclaration)">DTD schemas are unsupported in our flow; use a RelaxNG schema instead.</sch:assert>
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!