XQuery implementation of Schematron
Tested under BaseX 10.x.
- Install BaseX version 10 or later.
- Download the latest release and navigate to the root directory of the extracted archive (containing
*.xqm
and*.bxs
files).
XQS provides two methods of validating with a Schematron schema, by either:
- evaluating the schema dynamically; or
- compiling the schema to an XQuery main module.
Basic command scripts are provided to run XQS using BaseX in standalone mode. This allows you to use XQS as a straightforward, standalone validator.
The -b
options given below simply bind a variable; their order is not significant.
Run evaluate.bxs
, passing the locations of the XML document (uri
) and the Schematron schema (schema
):
basex -buri=myDoc.xml -bschema=mySchema.sch evaluate.bxs
You can also pass an optional phase (as phase
):
basex -buri=myDoc.xml -bschema=mySchema.sch -bphase=myPhase evaluate.bxs
The output is SVRL.
Run compile.bxs
, passing the location of the Schematron schema (schema
):
basex -bschema=mySchema.sch compile.bxs
You can also pass an optional phase:
basex -bschema=mySchema.sch -bphase=myPhase compile.bxs
Note a current limitation is that schema phase can only be specified during compilation and not at validation-time: see #7.
The output is an XQuery main module, which contains two external variables allowing the document to validate to be passed in:
$Q{http://www.andrewsales.com/ns/xqs}uri
$Q{http://www.andrewsales.com/ns/xqs}doc
$uri
should be a URI. If you XQuery processor supports it, you can use $doc
to pass a document node instead.
For convenience, if you have compiled a schema using compile.bxs
, you can run validate.bxs
, passing the schema and document locations:
basex -bschema=mySchema.xqy -buri=myDoc.xml
The output is again SVRL.
You can also use the XQuery API contained in xqs.xqm
, e.g.
import module namespace xqs = 'http://www.andrewsales.com/ns/xqs' at 'path/to/xqs.xqm;
xqs:validate(doc('myDoc.xml'), doc('mySchema.xml)/*[, 'myPhase'])
or
xqs:compile(doc('mySchema.xml)/*[, 'myPhase'])
This is a pre-release and should be treated as such. Please refer to the issues for a list of known bugs and planned enhancements.
Your schema must specify a queryBinding
value of : xquery
, xquery3
or xquery31
, in any combination of upper or lower case.
These are not yet supported: see #6. If your schema makes use of these, consider using a tool such as SchXslt to perform these steps in the meantime.
CAUTION When compiling, avoid using the XQS namespace (http://www.andrewsales.com/ns/xqs
) in your schema, which XQS uses for variables internal to the application.