Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSales committed Mar 16, 2024
1 parent 9a54584 commit f612212
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 12 deletions.
22 changes: 16 additions & 6 deletions schematron.sch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
© ISO/IEC 2017
© ISO/IEC 2024
The following permission notice and disclaimer shall be included in all
copies of this XML schema ("the Schema"), and derivations of the Schema:
Permission is hereby granted, free of charge in perpetuity, to any
Expand All @@ -21,37 +21,47 @@ THIS SCHEMA HAS BEEN MODIFIED FROM THE SCHEMA DEFINED IN ISO/IEC 19757 3,
AND SHOULD NOT BE INTERPRETED AS COMPLYING WITH THAT STANDARD."
-->

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xml:lang="en">
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xml:lang="en" queryBinding="xslt2">
<sch:title>Schema for Additional Constraints in Schematron</sch:title>
<sch:ns prefix="sch" uri="http://purl.oclc.org/dsdl/schematron"/>
<sch:p>This schema supplies some constraints in addition to those given in the
ISO/IEC 19757 2
(RELAX NG Compact Syntax) Schema for Schematron. </sch:p>
<sch:pattern>
<sch:rule context="sch:active">
<sch:assert test="//sch:pattern[@id=current()/@pattern]"> The pattern
<sch:assert test="//sch:pattern[@id=current()/@pattern]" id='active-patterns'> The pattern
attribute of the active element shall match the id
attribute of a pattern.</sch:assert>
</sch:rule>
<sch:rule context="sch:pattern[@is-a]">
<sch:assert test="//sch:pattern[@abstract='true'][@id=current()/@is-a]"> The
<sch:assert test="//sch:pattern[@abstract='true'][@id=current()/@is-a]" id="abstract-patterns"> The
is-a attribute of a pattern element shall match
the id attribute of an abstract pattern.
</sch:assert>
<sch:assert test="every $name in current()/sch:param/@name
satisfies $name eq //sch:pattern[@abstract='true'][@id=current()/@is-a]/sch:param/@name" id="param-names-match"> The
name attribute of a pattern param element shall match
the id attribute of an abstract pattern param element.
</sch:assert>
<sch:assert test="TODO: missing param value"></sch:assert>
</sch:rule>
<sch:rule context="sch:extends">
<sch:assert test="//sch:rule[@abstract='true'][@id=current()/@rule]"> The rule
<sch:assert test="//sch:rule[@abstract='true'][@id=current()/@rule]" id="abstract-rules"> The rule
attribute of an extends element shall match the id
attribute of an abstract rule.
</sch:assert>
</sch:rule>
<sch:rule context="sch:let">
<sch:assert
<sch:assert id="param-variable-clash"
test="not(//sch:pattern
[@abstract='true']/sch:param[@name=current()/@name])"
> A variable name and an abstract pattern parameter should not use the
same name.
</sch:assert>
</sch:rule>
<sch:rule context="sch:param">
<sch:assert test="not(../(sch:param except current())[@name=current()/@name])"
id="param-name">A parameter name should not use the same name as a parameter in the same scope.</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
87 changes: 81 additions & 6 deletions schematron.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,39 @@
-->
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec" xmlns:sch='http://purl.oclc.org/dsdl/schematron' schematron="schematron.sch">
<x:scenario label="demo-01">
<x:context><schema xmlns="http://purl.oclc.org/dsdl/schematron"><phase id='faulty'><active pattern="p1"
/></phase>
<phase id='fault-free'><active pattern="p2"
/></phase>
<x:context><schema xmlns="http://purl.oclc.org/dsdl/schematron">
<param name="myParam"/>
<param name="myParam"/>
<phase id='faulty'>
<active pattern="p1"/>
</phase>
<phase id='fault-free'>
<active pattern="p2"/>
</phase>
<pattern id="p2"/>
<pattern id='p3' is-a='foo'/>
<pattern id='p4' is-a='bar'/>
<pattern id='bar' abstract='true'/></schema></x:context>
<pattern id='p4' is-a='bar'>
<param name="blort"/>
<param name="not-declared"/>
</pattern>
<pattern id='bar' abstract='true'>
<param name='blort'/>
</pattern>
<pattern id="p5">
<let name='blort'/>
<let name='wibble'/>
<rule abstract='true' id='r1'/>
<extends rule='r1'/>
<extends rule='r2'/>
</pattern>
<pattern id='p6' abstract='true'>
<param name="blort"/>
<param name="blort"/>
</pattern>
<pattern id='p7' is-a='bar'>
<param name="blort"/>
</pattern>
</schema></x:context>

<x:scenario label="active pattern references">
<x:expect-not-assert
Expand All @@ -32,5 +57,55 @@
id="abstract-patterns"
location="/sch:schema[1]/sch:pattern[@id='p4']"/>
</x:scenario>

<x:scenario label="abstract rule references">
<x:expect-assert label="abstract rule missing"
id="abstract-rules"
location="/sch:schema/sch:pattern[@id='p5']/sch:extends[@rule='r2']"/>
<x:expect-not-assert label="abstract rule referenced correctly"
id="abstract-rules"
location="/sch:schema/sch:pattern[@id='p5']/sch:extends[@rule='r1']"/>
</x:scenario>

<x:scenario label="parameter variable name clash">
<x:expect-assert label="param variable name clash"
id="param-variable-clash"
location="/sch:schema/sch:pattern[@id='p5']/sch:let[@name='blort']"/>
<x:expect-not-assert label="param variable no name clash"
id="param-variable-clash"
location="/sch:schema/sch:pattern[@id='p5']/sch:let[@name='wibble']"/>
</x:scenario>

<x:scenario label="schema param dupe name">
<x:expect-assert label="duplicate schema param"
id="param-name"
location="/sch:schema/sch:param[1]"/>
<x:expect-assert label="duplicate pattern param"
id="param-name"
location="/sch:schema/sch:pattern[@id='p6']/sch:param[1]"/>
<x:expect-not-assert label="distinct pattern param"
id="param-name"
location="/sch:schema/sch:pattern[@id='bar']/sch:param[1]"/>
</x:scenario>

<!-- not-assert version of previous, with no duplicate schema params -->
<x:scenario label="schema param dupe name">
<x:context><sch:schema>
<sch:param name='pram1'/>
<sch:param name='pram2'/>
</sch:schema></x:context>
<x:expect-not-assert label="distinct schema param"
id="param-name"
location="/sch:schema/sch:param[1]"/>
</x:scenario>

<x:scenario label="concrete and abstract param names match">
<x:expect-assert label="param name not declared for abstract pattern"
id="param-names-match"
location="/sch:schema/sch:pattern[@id='p4']"/>
<x:expect-not-assert label="param name declared for abstract pattern"
id="param-names-match"
location="/sch:schema/sch:pattern[@id='p7']"/>
</x:scenario>
</x:scenario>
</x:description>

0 comments on commit f612212

Please sign in to comment.