Page 1 of 1
Multi-file Schematron architecture
Posted: Tue Apr 10, 2012 9:58 am
by brent3600
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.
Re: Multi-file Schematron architecture
Posted: Wed Apr 11, 2012 9:37 pm
by george
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
Re: Multi-file Schematron architecture
Posted: Thu Apr 12, 2012 5:59 am
by brent3600
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
Re: Multi-file Schematron architecture
Posted: Sun Jul 01, 2012 12:33 am
by brent3600
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 . . .
Re: Multi-file Schematron architecture
Posted: Mon Jul 02, 2012 11:11 am
by george
As far as I know there is not such XML parser for Java - if you find one let me know
![Smile :)](https://www.oxygenxml.com/forum/images/smilies/icon_smile.gif)
.
Re: Multi-file Schematron architecture
Posted: Sat Mar 28, 2015 6:59 pm
by Patrik
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
Re: Multi-file Schematron architecture
Posted: Wed Apr 01, 2015 2:01 pm
by radu_pisoi
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?
Re: Multi-file Schematron architecture
Posted: Thu Apr 02, 2015 10:45 am
by Patrik
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
Re: Multi-file Schematron architecture
Posted: Mon Jun 28, 2021 2:03 pm
by chrispitude
Hi everyone,
I have two smaller Schematron files that I would like to include from a main Schematron file:
Code: Select all
mainfile.sch ----+----> subfile1.sch
|
+----> subfile2.sch
Would iso:extends accomplish this? If so, can someone please post an example of the syntax and any necessary XML namespace declarations for iso:?
Thanks!
Re: Multi-file Schematron architecture
Posted: Tue Jun 29, 2021 4:49 pm
by chrispitude
Hi everyone,
I was able to resolve this with Radu's help:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
xmlns:sqf="http://www.schematron-quickfix.com/validator/process" xmlns:saxon="http://saxon.sf.net/">
<!-- include map and topic Schematron files -->
<extends href="snps_map_structure.sch"/>
<extends href="snps_topic_structure.sch"/>
</schema>
Schematron has an
<sch:include> element that seems promising by its name:
<sch:include href="...">
The required href attribute references an external well-formed XML document
whose document element is a Schematron element of a type which allowed by the grammar for
Schematron at the current position in the schema. The external document is inserted in place
of the include element.
However,
<sch:include> expects a file containing only a Schematron
element (like a
<pattern> or
<rule> element). In other words, it is for including Schematron fragments, not full Schematron files.
However, Schematron also has a less-intuitively-named
<sch:extends> element that includes an
entire Schematron file, which is what I needed:
<sch:extends href="...">
This element allows you to include components from another Schematron module.
The required href attribute references an external Schematron document.
The result is the inclusion of the top-level components from the referred Schematron document
into the current document.
WARNING: This element is experimental and it isn't included in ISO Schematron standard.
The descriptions above are found in the Schematron schema file at
<OXYGEN_HOME>/frameworks/schematron/impl/iso-schematron.xsd
They are also shown as element tooltips in the Oxygen XML Editor UI (but not Oxygen XML Author). I am thankful for Oxygen's tooltips, because I find Schematron documentation difficult to come by elsewhere!