Skip to content

Instantly share code, notes, and snippets.

@mkotelba
Created March 4, 2017 08:06
Show Gist options
  • Select an option

  • Save mkotelba/3dbc11c1377abde63a11813f7cea3836 to your computer and use it in GitHub Desktop.

Select an option

Save mkotelba/3dbc11c1377abde63a11813f7cea3836 to your computer and use it in GitHub Desktop.
ISO Schematron 2016 - RelaxNG Compact Schema + Schematron Files - Re-extracted/canonicalized
# Copyright © ISO/IEC 2015
# 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
# person obtaining a copy of the Schema, to use, copy, modify, merge and
# distribute free of charge, copies of the Schema for the purposes of
# developing, implementing, installing and using software based on the
# Schema, and to permit persons to whom the Schema is furnished to do so,
# subject to the following conditions:
# THE SCHEMA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SCHEMA OR THE USE OR
# OTHER DEALINGS IN THE SCHEMA.
# In addition, any modified copy of the Schema shall include the following
# notice:
# "THIS SCHEMA HAS BEEN MODIFIED FROM THE SCHEMA DEFINED IN ISO/IEC 19757-3,
# AND SHOULD NOT BE INTERPRETED AS COMPLYING WITH THAT STANDARD".
namespace local = ""
default namespace sch = "http://purl.oclc.org/dsdl/schematron"
start = schema
# Element declarations
schema =
element schema {
attribute id { xsd:ID }?,
rich,
attribute schemaVersion { non-empty-string }?,
attribute defaultPhase { xsd:IDREF }?,
attribute queryBinding { non-empty-string }?,
(foreign
& inclusion*
& (title?, ns*, p*, let*, phase*, pattern+, p*, diagnostics?, properties))
}
active =
element active {
attribute pattern { xsd:IDREF },
(foreign & (text | dir | emph | span)*)
}
assert =
element assert {
attribute test { exprValue },
attribute flag { flagValue }?,
attribute id { xsd:ID }?,
attribute diagnostics { xsd:IDREFS }?,
attribute properties { xsd:IDREFS }?,
rich,
linkable,
(foreign & (text | name | value-of | emph | dir | span)*)
}
diagnostic =
element diagnostic {
attribute id { xsd:ID },
rich,
(foreign & (text | value-of | emph | dir | span)*)
}
diagnostics = element diagnostics { foreign & inclusion* & diagnostic* }
dir =
element dir {
attribute value { "ltr" | "rtl" }?,
(foreign & text)
}
emph = element emph { text }
extends =
element extends {
(attribute rule { xsd:IDREF }
| attribute href { uriValue }),
foreign-empty
}
let =
element let {
attribute name { nameValue },
(attribute value { string }
| foreign-element+)
}
name =
element name {
attribute path { pathValue }?,
foreign-empty
}
ns =
element ns {
attribute uri { uriValue },
attribute prefix { nameValue },
foreign-empty
}
p =
element p {
attribute id { xsd:ID }?,
attribute class { classValue }?,
attribute icon { uriValue }?,
(foreign & (text | dir | emph | span)*)
}
param =
element param {
attribute name { nameValue },
attribute value { non-empty-string }
}
pattern =
element pattern {
attribute documents { pathValue }?,
rich,
(foreign
& inclusion*
& ((attribute abstract { "true" },
attribute id { xsd:ID },
title?,
(p*, let*, rule*))
| (attribute abstract { "false" }?,
attribute id { xsd:ID }?,
title?,
(p*, let*, rule*))
| (attribute abstract { "false" }?,
attribute is-a { xsd:IDREF },
attribute id { xsd:ID }?,
title?,
(p*, param*))))
}
phase =
element phase {
attribute id { xsd:ID },
rich,
(foreign & inclusion* & (p*, let*, active*))
}
properties = element properties { property* }
property =
element property {
attribute id { xsd:ID },
attribute role { roleValue }?,
attribute scheme { text }?,
(foreign & (text | name | value-of | emph | dir | span)*)
}
report =
element report {
attribute test { exprValue },
attribute flag { flagValue }?,
attribute id { xsd:ID }?,
attribute diagnostics { xsd:IDREFS }?,
attribute properties { xsd:IDREFS }?,
rich,
linkable,
(foreign & (text | name | value-of | emph | dir | span)*)
}
rule =
element rule {
attribute flag { flagValue }?,
rich,
linkable,
(foreign
& inclusion*
& ((attribute abstract { "true" },
attribute id { xsd:ID },
let*,
(assert | report | extends | p)+)
| (attribute context { pathValue },
attribute id { xsd:ID }?,
attribute abstract { "false" }?,
let*,
(assert | report | extends | p)+)))
}
span =
element span {
attribute class { classValue },
(foreign & text)
}
title = element title { (text | dir)* }
value-of =
element value-of {
attribute select { pathValue },
foreign-empty
}
# common declarations
inclusion =
element include {
attribute href { uriValue },
foreign-empty
}
rich =
attribute icon { uriValue }?,
attribute see { uriValue }?,
attribute fpi { fpiValue }?,
attribute xml:lang { langValue }?,
attribute xml:space { "preserve" | "default" }?
linkable =
attribute role { roleValue }?,
attribute subject { pathValue }?
foreign = foreign-attributes, foreign-element*
foreign-empty = foreign-attributes
foreign-attributes = attribute * - (local:* | xml:*) { text }*
foreign-element =
element * - sch:* {
(attribute * { text }
| foreign-element
| schema
| text)*
}
# Data types
uriValue = xsd:anyURI
pathValue = string
exprValue = string
fpiValue = string
langValue = xsd:language
roleValue = string
flagValue = string
nameValue = string
# In the default query language binding, xsd:NCNAME
classValue = string
non-empty-string = xsd:token { minLength = "1" }
<!--
© ISO/IEC 2015
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
person obtaining a copy of the Schema, to use, copy, modify, merge and
distribute free of charge, copies of the Schema for the purposes of
developing, implementing, installing and using software based on the
Schema, and to permit persons to whom the Schema is furnished to do so,
subject to the following conditions:
THE SCHEMA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SCHEMA OR THE USE OR
OTHER DEALINGS IN THE SCHEMA.
In addition, any modified copy of the Schema shall include the following
notice:
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: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
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
is-a attribute of a pattern element shall match
the id attribute of an abstract pattern.
</sch:assert>
</sch:rule>
<sch:rule context="sch:extends">
<sch:assert test="//sch:rule[@abstract='true'][@id=current()/@rule]"> 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
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:pattern>
</sch:schema>
# Copyright © ISO/IEC 2015
#
# 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
# person obtaining a copy of the Schema, to use, copy, modify, merge and
# distribute free of charge, copies of the Schema for the purposes of
# developing, implementing, installing and using software based on the
# Schema, and to permit persons to whom the Schema is furnished to do so,
# subject to the following conditions:
#
# THE SCHEMA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SCHEMA OR THE USE OR
# OTHER DEALINGS IN THE SCHEMA.
#
# In addition, any modified copy of the Schema shall include the following
# notice:
#
# THIS SCHEMA HAS BEEN MODIFIED FROM THE SCHEMA DEFINED IN ISO/IEC 19757-3,
# AND SHOULD NOT BE INTERPRETED AS COMPLYING WITH THAT STANDARD."
namespace local = ""
default namespace svrl = "http://purl.oclc.org/dsdl/svrl"
schematron-output =
element schematron-output {
attribute title { text }?,
attribute phase { xsd:NMTOKEN }?,
attribute schemaVersion { text }?,
human-text*,
ns-prefix-in-attribute-values*,
(active-pattern,
(fired-rule, (failed-assert | successful-report)*)+)+
}
# only namespaces from sch:ns need to be reported
ns-prefix-in-attribute-values =
element ns-prefix-in-attribute-values {
attribute prefix { xsd:NMTOKEN },
attribute uri { text },
empty
}
# only active patterns are reported
active-pattern =
element active-pattern {
attribute id { xsd:ID }?,
attribute documents { text }?,
attribute name { text }?,
attribute role { xsd:NMTOKEN }?,
empty
}
# only rules that are fired are reported,
fired-rule =
element fired-rule {
attribute id { xsd:ID }?,
attribute name { text }?,
attribute context { text },
attribute role { xsd:NMTOKEN }?,
attribute flag { xsd:NMTOKEN }?,
empty
}
# only references are reported, not the diagnostic
diagnostic-reference =
element diagnostic-reference {
attribute diagnostic { xsd:NMTOKEN },
human-text
}
# only failed assertions are reported
failed-assert =
element failed-assert {
attlist.assert-and-report, diagnostic-reference*, property-reference*, human-text
}
# only successful asserts are reported
successful-report =
element successful-report {
attlist.assert-and-report, diagnostic-reference*, property-reference*, human-text
}
# property-reference
property-reference =
element property-reference {
attribute property { xsd:NMTOKEN },
attribute role { text }?,
attribute scheme { text }?,
human-text
}
# human text
human-text =
element text {
attribute xml:space { text }?,
attribute xml:lang { text }?,
attribute see { text }?,
attribute icon { text }?,
attribute fpi { text }?,
rich-text
}
# rich text
rich-text = (foreign | dir | span | emph | text)*
# directionality
dir =
element dir {
attribute class { text }?,
attribute dir { text }?,
text
}
# emphasis
emph =
element emph {
attribute class { text }?,
text
}
# arbitrary markup
span =
element span {
attribute class { text },
text
}
# foreign
foreign = foreign-attributes | foreign-element
foreign-attributes = attribute * - (xml:* | local:*) { text }*
foreign-element =
element * - svrl:* {
(attribute * { text }
| foreign-element
| text)*
}
attlist.assert-and-report =
attribute id { xsd:ID }?,
attribute location { text },
attribute test { text },
attribute role { xsd:NMTOKEN }?,
attribute flag { xsd:NMTOKEN }?
start = schematron-output
<!--
Copyright © ISO/IEC 2014
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 person obtaining a
copy of the Schema, to use, copy, modify, merge and
distribute free of charge, copies of the Schema for the purposes of
developing, implementing, installing and using software based on the
Schema, and to permit persons to whom the Schema is furnished to do so,
subject to the following conditions:
THE SCHEMA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SCHEMA OR THE USE OR
OTHER DEALINGS IN THE SCHEMA.
In addition, any modified copy of the Schema shall include the following
notice:
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:title>Schema for Schematron Validation Report Language</sch:title>
<sch:ns prefix="svrl" uri="http://purl.oclc.org/dsdl/svrl"/>
<sch:p>The Schematron Validation Report Language is a simple language
for implementations to use to compare their conformance. It is
basically a list of all the assertions that fail when validating
a document, in any order, together with other information such as
which rules fire. </sch:p>
<sch:p>This schema can be used to validate SVRL documents, and provides examples
of the use of abstract rules and abstract patterns.</sch:p>
<sch:pattern>
<sch:title>Elements</sch:title>
<!--Abstract Rules -->
<sch:rule abstract="true" id="second-level">
<sch:assert test="../svrl:schematron-output"> The <sch:name/> element is a
child of schematron-output. </sch:assert>
</sch:rule>
<sch:rule abstract="true" id="childless">
<sch:assert test="count(*)=0"> The <sch:name/> element should not contain
any elements.
</sch:assert>
</sch:rule>
<sch:rule abstract="true" id="empty">
<sch:extends rule="childless"/>
<sch:assert test="string-length(space-normalize(.)) = 0"> The <sch:name/>
element should be empty. </sch:assert>
</sch:rule>
<!-- Rules-->
<sch:rule context="svrl:schematron-output">
<sch:assert test="not(../*)"> The <sch:name/> element is the root element.
</sch:assert>
<sch:assert
test="count(svrl:text) + count(svrl:ns-prefix-in-attribute-values)
+count(svrl:fired-rule) + count(svrl:failed-assert) +
count(svrl:successful-report) = count(*)">
<sch:name/> may only contain the following elements: text,
ns-prefix-in-attribute-values, active-pattern, fired-rule, failed-assert and
successful-report. </sch:assert>
<sch:assert test="svrl:active-pattern">
<sch:name/> should have at least one active pattern. </sch:assert>
</sch:rule>
<sch:rule context="svrl:text">
<sch:extends rule="childless"/>
</sch:rule>
<sch:rule context="svrl:diagnostic-reference">
<sch:extends rule="childless"/>
<sch:assert test="string-length(@diagnostic) &gt; 0">
<sch:name/> should have a diagnostic attribute, giving the id of
the diagnostic.
</sch:assert>
</sch:rule>
<sch:rule context="svrl:ns-prefix-in-attribute-values">
<sch:extends rule="second-level"/>
<sch:extends rule="empty"/>
<sch:assert
test="following-sibling::svrl:active-pattern
or following-sibling::svrl:ns-prefix-in-attribute-value"
> A <sch:name/> comes before an active-pattern or another
ns-prefix-in-attribute-values element. </sch:assert>
</sch:rule>
<sch:rule context="svrl:active-pattern">
<sch:extends rule="second-level"/>
<sch:extends rule="empty"/>
</sch:rule>
<sch:rule context="svrl:fired-rule">
<sch:extends rule="second-level"/>
<sch:extends rule="empty"/>
<sch:assert
test="preceding-sibling::active-pattern |
preceding-sibling::svrl:fired-rule |
preceding-sibling::svrl:failed-assert |
preceding-sibling::svrl:successful-report"
> A <sch:name/> comes after an active-pattern, an empty fired-rule,
a failed-assert or a successful report. </sch:assert>
<sch:assert test="string-length(@context) &gt; 0"> The <sch:name/> element
should have a context attribute giving the current
context, in simple XPath format. </sch:assert>
</sch:rule>
<sch:rule context="svrl:failed-assert | svrl:successful-report">
<sch:extends rule="second-level"/>
<sch:assert test="count(svrl:diagnostic-reference) + count(svrl:text) =
count(*)"> The <sch:name/> element should only contain a
text element and diagnostic reference elements. </sch:assert>
<sch:assert test="count(svrl:text) = 1"> The <sch:name/> element should only
contain a text element. </sch:assert>
<sch:assert
test="preceding-sibling::svrl:fired-rule |
preceding-sibling::svrl:failed-assert |preceding-sibling::svrl:successful-
report"
> A <sch:name/> comes after a fired-rule, a failed-assert or a successful-
report.
</sch:assert>
</sch:rule>
<!-- Catch-all rule-->
<sch:rule context="*">
<sch:report test="true()"> An unknown <sch:name/> element has been used.
</sch:report>
</sch:rule>
</sch:pattern>
<sch:pattern>
<sch:title>Unique Ids</sch:title>
<sch:rule context="*[@id]">
<sch:assert test="not(preceding::*[@id=current()/@id][1]"> Id attributes
should be unique in a document. </sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern abstract="true" id="requiredAttribute">
<sch:title>Required Attributes</sch:title>
<sch:rule context=" $context ">
<sch:assert test="string-length( $attribute ) &gt; 0"> The <sch:name/> element
should have a <sch:value-of select="$attribute /name()"/> attribute.
</sch:assert>
</sch:rule>
</sch:pattern>
<sch:pattern is-a="requiredAttribute">
<sch:param name="context" value="svrl:diagnostic-reference"/>
<sch:param name="attribute" value="@diagnostic"/>
</sch:pattern>
<sch:pattern is-a="requiredAttribute">
<sch:param name="context" value="svrl:failed-assert or svrl:successful-report"/>
<sch:param name="attribute" value="@location"/>
</sch:pattern>
<sch:pattern is-a="requiredAttribute">
<sch:param name="context" value="svrl:failed-assert or svrl:successful-report"/>
<sch:param name="attribute" value="@test"/>
</sch:pattern>
<sch:pattern is-a="requiredAttribute">
<sch:param name="context" value="svrl:ns-prefix-in-attribute-values"/>
<sch:param name="attribute" value="@uri"/>
</sch:pattern>
<sch:pattern is-a="requiredAttribute">
<sch:param name="context" value="svrl:ns-prefix-in-attribute-values"/>
<sch:param name="attribute" value="@prefix"/>
</sch:pattern>
</sch:schema>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment