Search code examples
xmlxsdschematronoxygenxml

Include Schema validation (.xsd) in Schematron validation (.sch) [not the other way around]


Since it is easier and less verbose to enforce data structure in an XSD file than it is in a Schematron and since we already have working XSD files to validate single entities, I would like to include these as a first validation phase in my Schematron.

I found tutorials describing the other way around (embedded Schematron rules in XSD).

I found the element <sch:include href="my.xsd"> but when I validate (with oXygen) it does not seem to make a difference.

It seems I am missing something very obvious as this should be supported without problems or shouldn't it?


Solution

  • Well, there is as far as I know, no concept to include XSD in Schematron. But as you can embed XSLT in Schematron and XSLT schema-aware is able to validate your input data, you can use xsl:import-schema:

    <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
    
        <xsl:import-schema schema-location="path/to/my.xsd"/>
    
        <!-- [your schematron rules] -->
    </sch:schema>
    

    In oXygen you need to activate schema-aware for Schematron validations:

    Preferences -> XML -> XML-Parser -> Schematron -> Use Saxon EE (schema-aware) for xslt2/xslt3 query language binding.