SchXslt is copyright (c) by David Maus <[email protected]> and released under the terms of the MIT license.
SchXslt is a Schematron processor implemented entirely in XSLT. It transforms a Schematron schema document into an XSLT stylesheet that you apply to the document(s) to be validated.
As of date SchXslt does not properly implement the scoping rules of pattern (see #135) and phase variables (see #136).
Schema, pattern, and phase variables are all implemented as global XSLT variables. As a consequence the name of a schema, pattern, or phase variable must be unique in the entire schema.
Due to the constrains of XSLT 1.0 and the way rules are implemented it is not possible to use a variable inside a rule context expression of a Schematron using the XSLT 1.0 query binding (see #138).
When an external construct is incorporated withsch:include
orsch:extends
by its@xml:id
attribute,
the namespace bindings of the include target document are not preserved (#343 #344).
Thesvrl:active-patterns/@documents
attribute does not contain the URIs of the subordinate documents (#342).
SchXslt implements the following Schematron enhancements:
The Schematron specification does not allow for annotating variables with the expected type of its value. Type annotations are helpful to make the most of XSLT 3.0. Using them is current best practice.
This proposal adds support for an@as
attribute on variable declarations.
The Schematron specification limits the the reuse of abstract rules to the current pattern element. The@href attribute
onextends
was introduced in 2016 to overcome this limitation but requires a schema author to
externalize abstract rules for them to be used.
This proposal extends Schematron with a top-levelrules
element to hold abstract rules that are globally
referencable by the@rule
attribute ofextends
.
The Schematron specification allows the XSLT elementsfunction
andkey
to be used in a Schematron
schema. This makes sense because both are required to set up the query language environment. Thekey
element
prepares data structures for thekey()
function and thefunction
element allows the use of user defined
functions.
This proposal adds support for the following XSLT elements:
- xsl:accumulator (XSLT 3.0)
- xsl:import (XSLT 1.0, XSLT 2.0, XSLT 3.0)
- xsl:import-schema (XSLT 2.0, XSLT 3.0)
- xsl:include (XSLT 1.0, XSLT 2.0, XSLT 3.0)
- xsl:use-package (XSLT 3.0)
Depending on your environment there are several ways to install SchXslt.
-
Starting with version 1.5 every release onthis repository's release pageprovides a ZIP file with just the XSLT stylesheets. This page also provides a ZIP file with the XSLT stylesheets and twoXProc 1.0steps. Just download and unzip.
-
A Java package is published toMaven Central.Use it with Maven or the Java dependency management tool of your choice.
-
If you useBaseXoreXistyou can download installable XQuery modulesq fromthis repository's release pageas well.
SchXslt uses theMavenbuild tool to create installable packages. To create the packages for
yourself clone this repository, installMavenand run it with thepackage
phase.
dmaus@carbon ~ % git clone --recursive https://github.com/schxslt/schxslt.git
Cloning into 'schxslt'...
remote: Enumerating objects: 450, done.
remote: Counting objects: 100% (450/450), done.
remote: Compressing objects: 100% (298/298), done.
remote: Total 3789 (delta 172), reused 374 (delta 111), pack-reused 3339
Receiving objects: 100% (3789/3789), 470.87 KiB | 1.05 MiB/s, done.
Resolving deltas: 100% (1607/1607), done.
dmaus@carbon ~ % mvn package
This runs the unit tests and creates the following files:
- ant/target/ant-schxslt-{VERSION}.jar (Java archive)
- cli/target/schxslt-cli.jar (Java archive)
- core/target/schxslt-{VERSION}.jar (Java archive)
- core/target/schxslt-{VERSION}-xslt-only.zip (ZIP file with stylesheets)
- exist/target/schxslt-exist-{VERSION}.xar (XQuery package for eXist)
- basex/target/schxslt-basex-{VERSION}.xar (XQuery package for BaseX)
Where {VERSION} is replaced with the current SchXslt version.
The simplest way to use SchXslt is to download the ZIP file with just the stylesheets from the
releasespage. To validate documents with your Schematron you first
transform it with thepipeline-for-svrl.xsl
stylesheet. This creates the XSL transformation that creates a
validation report when applied to a document.
To use SchXslt in your Java application define the following Maven dependency:
<dependency>
<groupId>name.dmaus.schxslt</groupId>
<artifactId>schxslt</artifactId>
<version>{VERSION}</version>
</dependency>
Where {VERSION} is replaced with the current SchXslt version.
Also take a look atSchXslt Java,a set of Java classes for Schematron validation with SchXslt.
The XQuery module provides a functionschxslt:validate()
that validates a document and returns a validation report
expressed in the Schematron Validation Report Language (SVRL). You import the module using its namespace URI.
import module namespace schxslt = "https://doi.org/10.5281/zenodo.1495494";
let $document:= <ex:example xmlns:ex= "https://example.com/ns" />
let $schema:=
<sch:schema xmlns:sch= "http://purl.oclc.org/dsdl/schematron" queryBinding= "xslt2" >
<sch:pattern>
<sch:rule context= "/" >
<sch:assert test= "true()" >Always true</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
return
schxslt:validate($document, $schema)
The Ant module implements a task forApache Antthat performs Schematron validation with
SchXslt. Download or compile the Jar file and define a new task usingname.dmaus.schxslt.ant.Task
as class name.
<project name= "Test" basedir= "." default= "build" >
<taskdef name= "schematron" classname= "name.dmaus.schxslt.ant.Task" classpath= "/path/to/ant-schxslt-{VERSION}.jar" />
<target name= "build" >
<schematron schema= "schema.sch" file= "document.xml" report= "report.xml" phase= "myPhase" />
</target>
</project>
The task supports the following options:
file | Path to the file to be validated | - |
---|---|---|
schema | Path to the file containing the Schematron | - |
phase | Validation phase | #ALL |
report | Path to the file that the SVRL report should be written to |
SchXslt Ant usesXML Resolverto support XML Catalog resolvers.
The CLI module provides a command line program for performing Schematron validation with SchXslt. Download or compile
the Jar fileschxslt-cli.jar
.
To validate the XML documentdocument.xml
against the schema inschema.sch
with the report written to
report.xml
you can run:
java -jar schxslt-cli.jar -d document.xml -s schema.sch -o report.xml
The command line option-h
lists all available options.
SchXslt CLI v1.10
usage: name.dmaus.schxslt.cli.Application [-d <arg>] [-e <arg>] [-o <arg>]
[-p <arg>] [-r] -s <arg> [-v]
-d,--document <arg> Path to document
-e,--exitcode <arg> Use exit code to indicate invalid document
(default is 0)
-o,--output <arg> Output file (SVRL report)
-p,--phase <arg> Validation phase
-r,--repl Run as REPL
-s,--schematron <arg> Path to schema
-v,--verbose Verbose output