Multi-file Schematron architecture

This should cover W3C XML Schema, Relax NG and DTD related problems.
brent3600
Posts: 3

Multi-file Schematron architecture

Tue Apr 10, 2012 9:58 am

I am trying to figure out how to construct a set of Schematron files that work together. For example, where an abstract pattern can reside in one Schematron schema and can be invoked by a pattern in another schema. Or where a set of schemas can be processed against an instance document using a single processing instruction in the instance message. I'm sure someone has already thought this out, and I'm hoping someone can point me in the right direction. I've considered the following possibilities:

My first thought was just to put multiple processing instructions in the instance messages, but it turns out that we can't do that.

My second thought was to simply invoke one schema from another using a namespace, ala "import" statements in XML Schema, but Schematron doesn't seem to be set up for that.

My third thought was to use include statements to pull content into a schema from external files. The problem is that whatever an include statement brings in has to fit into the Schematron hierarchy at the point of insertion. So from a schema you can include a pattern, but you can't include a schema. Supposedly you can set up include statements to include a specific entity in a file, and not the whole file, but I get error messages telling me I can't do that when I try it.

My fourth thought was to extend Schematron to create a layer between schema and pattern, phase, etc., which would facilitate "including" the entire contents of a schema without including the schema itself. I don't know how to do this.

So at this point I'm contemplating a setup where every pattern and abstract pattern "lives" in a separate file which gets included in a single schematron file. This could be workable but presents major complexity and management issues, obviously. I have the feeling that there must be a straight-forward way to do this.

Any pointers you can toss my way would be much appreciated.
george
Site Admin
Posts: 2100

Re: Multi-file Schematron architecture

Wed Apr 11, 2012 9:37 pm

Hi,

You summarized very well the possibilities. It is a pity that the include Schematron element did not work as many people expect that to work, that is to refer to a schema and to include all the patterns that are found in that schema.
AFAIK for the next version of Schematron there is a new Schematron element proposed that will perform exactly that processing.

One possibility is to use XInclude to bring in the patterns you want, but I am afraid that only the element XPointer scheme will work. Something like below:

test.xml

Code: Select all

<?xml-model href="test.sch" type="application/xml"
  schematypens="http://purl.oclc.org/dsdl/schematron"?>
<test>
 
</test>


test.sch

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="inc.sch" xpointer="element(/1/1)"/>
  <pattern id="p2" is-a="p1">
  </pattern>
</schema>


inc.sch

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
  <pattern id="p1" abstract="true">
    <rule context="test">
      <assert test="false()">test..</assert>
    </rule>
  </pattern>
</schema>


Best Regards,
George
George Cristian Bina
brent3600
Posts: 3

Re: Multi-file Schematron architecture

Thu Apr 12, 2012 5:59 am

Thanks so much, George, for your thoughtful and detailed reply! Very useful. It sounds like a good solution. I'll try it out and let you know how it works for me. I really appreciate your taking the time to lay it out so well.

- Brent
brent3600
Posts: 3

Re: Multi-file Schematron architecture

Sun Jul 01, 2012 12:33 am

The suggested approach still looks good, but I've run into a problem. It would appear that Xerces only supports the XPointer element scheme, not the full XPointer standard. In particular, the XPath scheme in XPointer is not supported. Is there an alternative XML parser that supports XML Schema, Schematron, XInclude, XPath, and XPointer, specifically the XPath scheme in the latter? And that can be attached to Oxygen . . .
george
Site Admin
Posts: 2100

Re: Multi-file Schematron architecture

Mon Jul 02, 2012 11:11 am

As far as I know there is not such XML parser for Java - if you find one let me know :).
George Cristian Bina
Patrik
Posts: 216
Location: Hamburg/Germany

Re: Multi-file Schematron architecture

Sat Mar 28, 2015 6:59 pm

Hi,

I had a similar problem with a growing schematron file I'd like to split.

Since it seems like there wont be a new schematron version any time soon I modified the files included in oxygen myself. Maybe you could consider adding this to the oxygen distribution as well:

customized-iso-schematron.xsd:

Code: Select all

<xs:element name="schema">
   [...]
   <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
         [...]
         <xs:element ref="sch:include-schema"/>
         [...]
      </xs:choice>
      [...]
   </xs:complexType>
</xs:element>
[...]
<xs:element name="include-schema">
   <xs:annotation>
      <xs:documentation> The required href attribute references an external well-formed XML
         document whose document element is a Schematron schema. It's content is inserted
         in place of this include-schema element. </xs:documentation>
   </xs:annotation>
   <xs:complexType>
      <xs:attribute name="href" use="required" type="sch:uriValue">
         <xs:annotation>
            <xs:documentation> References an external well-formed XML
               document.</xs:documentation>
         </xs:annotation>
      </xs:attribute>
   </xs:complexType>
</xs:element>


schematronDispatcher.xsd:

Code: Select all

<xsl:template match="sch:include-schema" mode="resolveIncludes">
   <xsl:variable name="doc" select="document(@href, .)"/>
   <xsl:choose>
      <xsl:when test="not($doc)">
         <xsl:message terminate="no">
            <xsl:text>Error:Unable to open referenced included file: </xsl:text>
            <xsl:value-of select="@href"/>
         </xsl:message>
      </xsl:when>
      <xsl:when test="not($doc/sch:schema)">
         <xsl:message terminate="no">
            <xsl:text>Error:The Schematron include-schema should point to a schema element: </xsl:text>
            <xsl:value-of select="@href"/>
         </xsl:message>
      </xsl:when>
      <xsl:when test="$doc/sch:schema/@queryBinding != /sch:schema/@queryBinding">
         <xsl:message terminate="no">
            <xsl:text>Error:The Schematron include-schema should point to a schema element with the same queryBinding as the including schema: </xsl:text>
            <xsl:value-of select="@href"/>
            <xsl:text>, queryBinding: '</xsl:text>
            <xsl:value-of select="$doc/sch:schema/@queryBinding"/>
            <xsl:text>' instead of '</xsl:text>
            <xsl:value-of select="/sch:schema/@queryBinding"/>
            <xsl:text>'</xsl:text>
         </xsl:message>
      </xsl:when>
   </xsl:choose>
   <xsl:apply-templates select="$doc/sch:schema/sch:*" mode="resolveIncludes"/>
</xsl:template>


If you know a promising way to contribute this change (and more to come) to a new version of schematron I would gladly share my code...

Regards,

Patrik
radu_pisoi
Posts: 310
Location: Craiova

Re: Multi-file Schematron architecture

Wed Apr 01, 2015 2:01 pm

Thank you for your feedback and your willingness to share your ideas and code with us.

In oXygen 16.1 we improved the inclusion mechanism when working with ISO Schematron modules by adding support for iso:extends element. This element allows you to include all the components defined in a Schematron schema (such as patterns or phases) as opposed to the standard inclusion mechanism defined in ISO Schematron (iso:include element) that allows you to include the root element of the included Schematron module.

Did you try to use the iso:extends element?
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Patrik
Posts: 216
Location: Hamburg/Germany

Re: Multi-file Schematron architecture

Thu Apr 02, 2015 10:45 am

Hi Radu,

thanks for the hint. I could just replace my include-schema with extends and it worked the same way. Thus, my include-schema is obsolete.

Regards,
Patrik

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 1 guest