David Maus dmaus@dmaus.name
TEI Member's Meeting 2019
https://github.com/dmj/workshop-tei2019-public
The @to and @notAfter attributes cannot be used together.
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern>
<rule context="tei:*[@to]">
<report test="@notAfter" role="nonfatal">
The @to and @notAfter attributes cannot be used together.
</report>
</rule>
</pattern>
</schema>
File: examples/1-introduction/1-attributes.sch
Every footnote must end with a punctuation mark.
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern>
<rule context="tei:note[@type='footnote']">
<assert test="ends-with(., '.') or ends-with(., '?') or ends-with(., '!')">
A footnote must end with a punctuation mark.
</assert>
</rule>
</pattern>
</schema>
File: examples/1-introduction/2-footnote.sch
Tell me if the document contains characters that require a special font to render correctly.
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<pattern>
<rule context="text()|@*">
<report test="matches(., '\p{Co}')" role="info">
This element or attribute contains characters
from the Unicode Private Use Area.
</report>
</rule>
</pattern>
</schema>
File: examples/1-introduction/3-unicode.sch
Schematron is a feather duster to reach the corners that other schema languages cannot reach.
schxslt-cli.jar
in the workshop's bin/
folder
java -jar bin/schxslt-cli.jar
usage: name.dmaus.schxslt.cli.Main [-d ] [-o ] [-p ] [-r] -s [-v]
-d,--document Path to document
-o,--output Output file (SVRL report)
-p,--phase Validation phase
-r,--repl Run as REPL
-s,--schematron Path to schema
-v,--verbose Verbose output
p:validate-with-schematron
schema
title?
p*
ns*
pattern+
rule+
(assert | report)+
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>Example schema</title>
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
…
</pattern>
</schema>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>Example schema</title>
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
…
</pattern>
</schema>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>Example schema</title>
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
…
</pattern>
</schema>
xslt
(default) or xslt2
xslt2
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>Example schema</title>
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
…
</pattern>
</schema>
p
for paragraphs<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>Example schema</title>
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
…
</pattern>
</schema>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<title>Example schema</title>
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>…</pattern>
</schema>
@context
matches a
node<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
<rule context="tei:titleStmt">…</rule>
<rule context="@ref">…</rule>
<rule context="text()">…</rule>
</pattern>
</schema>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
<rule context="tei:titleStmt" role="info">…</rule>
<rule context="@ref">…</rule>
<rule context="text()">…</rule>
</pattern>
</schema>
@role
allows for a classification of the ruleinfo
, warn
, error
etc.@test
attribute
evaluates to false the assertion is unmet and will be reported
@test
attribute
evaluates to true the assertion is met and will be reported
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<ns prefix="tei" uri="http://www.tei-c.org/ns/1.0"/>
<pattern>
<rule context="tei:titleStmt">
<assert test="empty(tei:title[@type = 'short']/tei:*)">…</assert>
</rule>
<rule context="text()">
<report test="contains(., '...') or contains(., '…')">…</report>
</rule>
</pattern>
</schema>
File: examples/2-core/1-assertions.sch
name
(name of the context node)
and value-of
elements (arbitrary XPath expression)if-then-else
statementexamples/2-core/02-rule-order-error.sch
does not fire because the titleStmt
was
already matched by the first rule03-…
to 05-…
present different solutions to the problem@value
is avaluated in the context of a
rule or the XML document, depending on where it is definedChild of | Context | Scope |
---|---|---|
schema | document root | global |
pattern | document root | pattern |
rule | node selected by @context |
rule |
examples/3-advanced/01-let.sch
@abstract
to 'true'@context
@context
is provided by a rule that extends an abstract ruleexamples/3-advanced/03-abstract-rule.sch
@abstract
to 'true'examples/3-advanced/04-abstract-pattern.sch
examples/4-quickfix/xx-complete.xml
assert
sqf:fix*
sqf:description
sqf:title
( sqf:add | sqf:delete | sqf:replace | sqf:replaceString )
examples/4-quickfix/01-add-attribute.sch
examples/4-quickfix/02-user-entry.sch
examples/4-quickfix/03-del-attribute.sch
examples/4-quickfix/04-unwrap-elements.sch