Loading TOC...

schematron.validate

schematron.validate(
   document as Node,
   validator-xslt as Node
) as Node

Summary

This function accepts the document to be validated and the validator XSLT and returns the output of the validation in SVRL (Schematron Validation Report Language) format, which is a simple XML based language used to report the results of Schematron validation.

Parameters
document The document to be validated.
validator-xslt The validator XSLT.

Example


//Insert the document to be validated
declareUpdate();
xdmp.documentInsert("request001.json",
{
  "request" : {
    "id" : "001",
    "description" : "bedroom door knob broken",
    "maintainance" : "yes",
    "fixed" : "yes",
    "raisedBy" : "Alan Rick",
    "category" : "doors",
    "fixedBy" : "Ron"
  }
})    

//Validate the document
const schematron = require("/MarkLogic/schematron/schematron.xqy");

schematron.validate(fn.doc("request001.json"),schematron.get("/requestSchema.sch"))

==>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svrl:schematron-output title="request-validation" schemaVersion="1.0" phase="phase2" 
  xmlns:schold="http://www.ascc.net/xml/schematron" 
  xmlns:iso="http://purl.oclc.org/dsdl/schematron" 
  xmlns:xhtml="http://www.w3.org/1999/xhtml" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" 
  xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
  <!--   
       
       
  -->
<svrl:active-pattern document="request001.json" id="co-occurence" name="co-occurence"/>
<svrl:fired-rule context="request"/>
<svrl:failed-assert test="(category = 'doors' and fixedBy = 'Tom') or (category != 'doors')" location="/request">
  <svrl:text>if category is doors then fixedBy must be Tom</svrl:text>
  <svrl:diagnostic-reference diagnostic="d1">
Requests of doors category should be fixed by Tom</svrl:diagnostic-reference>
  </svrl:failed-assert>
</svrl:schematron-output>
 
    

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.