schematron.put( schematron-uri as String, [params as Object?] ) as null
This function compiles the Schematron schema with $schematron-uri
as the
URI of the Schematron document in the schema database and inserts the generated
validator XSLT in the modules database with the URI, {$schematron-uri}-validator.xsl
.
For example, if the URI of the Schematron document is /schematron.sch
, the URI of the
validator XSLT will be /schematron.sch-validator.xsl
. If the Schematron schema
is not found, an SCHEMATRON-SCHEMANOTFOUND
error is thrown. If Schematron schema
is bad, the appropriate error is thrown.
Possible Errors | |
---|---|
SCHEMATRON-SCHEMANOTFOUND |
No document exists in the Schema database with the document URI specified. |
SCHEMATRON-VALIDATORNOTFOUND |
The Schematron is not compiled and stored. |
SCHEMATRON-NAMESPACE |
Schematron schema uses both old and new namespaces. |
SCHEMATRON-QRYBINDING |
Invalid value for queryBinding attribute is specified. |
SCHEMATRON-PHASE |
No phase has been defined with given the name. |
SCHEMATRON-ACTIVE-NOPATTERN |
The active element has no pattern attribute. |
SCHEMATRON-PATTERNREFERENCE |
Pattern declaration missing. |
SCHEMATRON-ASSERT-NOTEST |
The assert element has no test attribute. |
SCHEMATRON-REPORT-NOTEST |
The report element has no test attribute. |
SCHEMATRON-DIAGNOSTIC-NOID |
The diagnostic element has no id attribute. |
SCHEMATRON-EXTENDS-NORULE |
Declaration of abstract rule missing. |
SCHEMATRON-RULEREFERENCE |
Abstract rule declaration missing. |
SCHEMATRON-KEY-NONAME |
The key element has no name attribute. |
SCHEMATRON-KEY-NOPATHORUSE |
The key element has no path or use attribute. |
SCHEMATRON-KEY |
The key element is in the ISO Schematron namespace. |
SCHEMATRON-FUNCTION-NONAME |
The function element has no name attribute. |
SCHEMATRON-FUNCTION |
The function element in the ISO Schematron namespace. |
SCHEMATRON-INCLUDEEMPTY |
Empty value for the href attribute in the include directive. |
SCHEMATRON-INCLUDEBADURL |
Include directive contains a bad URL. |
SCHEMATRON-INCLUDEBAD |
Unable to include the document referenced by include directive |
SCHEMATRON-INCLUDE |
Include directive is used to reference the whole schema. |
SCHEMATRON-CANNOTIMPORTSCHEMA |
Element import-schema is used for a query language binding that is not 'xslt2' |
SCHEMATRON-IMPORTSCHEMA |
The import-schema element is in the ISO Schematron namespace. |
SCHEMATRON-VARIABLES |
Incorrect use of variables. |
SCHEMATRON-NS-NOURI |
The ns element has no uri attribute. |
SCHEMATRON-NS-NOPREFIX |
The ns element has no prefix attribute. |
SCHEMATRON-ABSTRACTPATTERNS |
Abstract patterns have not been pre-processed. |
SCHEMATRON-PHASE-NOID |
The phase element has no id attribute. |
SCHEMATRON-RULE-NOCONTEXT |
The rule element has no context attribute. |
SCHEMATRON-ABSTRACTRULE-NOID |
The abstract rule has no id attribute. |
SCHEMATRON-ABSTRACTRULE-CONTEXT |
The abstract rule has has context attribute. |
SCHEMATRON-VALUEOF-NOSELECT |
The value element has no select attribute. |
SCHEMATRON-HASCHILD |
Child element is unexpected for the given element. |
SCHEMATRON-DIAGNOSTICREFERENCE |
Diagnostic declaration missing. |
SCHEMATRON-UNKNOWN-SCHMTRNELEMENT |
Unknown Schematorn element is present. |
SCHEMATRON-UNKNOWNELEMENT |
Unknown element is present. |
SCHEMATRON-BAD |
Bad Schema. |
// Insert the Schematron schema in the schema database. // Note that line returns on XML schema files need to be escaped in javaScript. // Note that the queryBinding="xslt2" attribute in the schema file directs Schematron to make // use of the xslt 2.0 engine. declareUpdate(); const schema = fn.head(xdmp.unquote('<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" \ queryBinding="xslt2" schemaVersion="1.0">\ <sch:title>request-validation</sch:title>\ <sch:phase id="phase1">\ <sch:active pattern="structural"></sch:active>\ </sch:phase>\ <sch:phase id="phase2">\ <sch:active pattern="co-occurence"></sch:active>\ </sch:phase>\ <sch:pattern id="structural">\ <sch:rule context="request">\ <sch:assert test="id">request should have an id</sch:assert>\ <sch:assert test="count(*) = 7">request should have 7 properties: \ id, description, maintainance, fixed, raisedBy, category and fixedBy \ </sch:assert>\ </sch:rule>\ </sch:pattern>\ <sch:pattern id="co-occurence">\ <sch:rule context="request">\ <sch:assert test="(category = \'doors\' and fixedBy = \'Tom\') \ or (category != \'doors\')" diagnostics="d1"> \ if category is doors then fixedBy must be Tom \ </sch:assert>\ </sch:rule>\ </sch:pattern>\ <sch:diagnostics>\ <sch:diagnostic id="d1">Requests of doors category should be fixed by Tom</sch:diagnostic>\ </sch:diagnostics>\ </sch:schema>')) xdmp.documentInsert("/requestSchema.sch", schema.root) //schematron.put in the documents database const schematron = require("/MarkLogic/schematron/schematron.xqy"); const params = { "phase" : "phase2", "terminate" : false, "generate-fired-rule" : true, "generate-paths" : true, "diagnose" : true, "allow-foreign" : false, "validate-schema" : true } schematron.put("/requestSchema.sch", params) ==> inserts the compiled Schematron schema (validator XSLT) in the Schemas database and returns empty sequence
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.