schematron.compile( schema as element(sch.schema), [params as Object?] ) as Node
This function compiles the Schematron schema. The Schematron schema is preprocessed and converted into the validator XSLT and returned. This function performs the first three stages of ISO Schematron. It accepts the Schematron root element and returns the document node of the XSLT validator script. This function will also optionally accept a map of parameters. The string key represents the parameter and each entry represents the value of the parameter.
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. |
// Note that the queryBinding="xslt2" attribute in the schema file directs Schematron to make // use of the xslt 2.0 engine. // Note that line returns on XML schema files need to be escaped in javaScript. const schematron = require("/MarkLogic/schematron/schematron.xqy"); 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>')) const params = { "phase" : "phase2", "terminate" : false, "generate-fired-rule" : true, "generate-paths" : true, "diagnose" : true, "allow-foreign" : false, "validate-schema" : true } schematron.compile(schema.root, params) ==> returns the compiled Schematron schema (validator XSLT)