schematron:compile( $schema as element(sch:schema), [$params as map:map?] ) as document-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. :) xquery version "1.0-ml"; import module namespace schematron = "http://marklogic.com/xdmp/schematron" at "/MarkLogic/schematron/schematron.xqy"; let $schema := <sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2" schemaVersion="1.0"> <sch:title>user-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="user"> <sch:assert test="@id">user element should have an id attribute</sch:assert> <sch:assert test="count(*) = 5"> user element should have 5 child elements: name, gender, age, score and result </sch:assert> <sch:assert test="score/@total">score element should have a total attribute</sch:assert> <sch:assert test="score/count(*) = 2">score element should have two child elements</sch:assert> </sch:rule> </sch:pattern> <sch:pattern id="co-occurence"> <sch:rule context="score"> <sch:assert test="@total = test-1 + test-2">total score must be a sum of test-1 and test-2 scores</sch:assert> <sch:assert test="(@total gt 30 and ../result = 'pass') or (@total le 30 and ../result = 'fail')" diagnostics="d1"> if the score is greater than 30 then the result should be 'pass' else 'fail' </sch:assert> </sch:rule> </sch:pattern> <sch:diagnostics> <sch:diagnostic id="d1">the score does not match with the result</sch:diagnostic> </sch:diagnostics> </sch:schema> let $params := map:map() let $_put := map:put($params, 'phase', '#ALL') let $_put := map:put($params, 'terminate', fn:false()) let $_put := map:put($params, 'generate-fired-rule', fn:true()) let $_put := map:put($params, 'generate-paths', fn:true()) let $_put := map:put($params, 'diagnose', fn:true()) let $_put := map:put($params, 'allow-foreign', fn:false()) let $_put := map:put($params, 'validate-schema', fn:true()) return schematron:compile($schema, $params) ==> returns the compiled Schematron schema (validator XSLT)