schematron:validate( $document as node(), $validator-xslt as document-node() ) as document-node()
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. |
(:Insert the document to be validated:) xdmp:document-insert("user001.xml", <user id="001"> <name>Alan</name> <gender>Male</gender> <age>14</age> <score total="90"> <test-1>50</test-1> <test-2>40</test-2> </score> <result>fail</result> </user>) (:Validate the document:) xquery version "1.0-ml"; import module namespace schematron = "http://marklogic.com/xdmp/schematron" at "/MarkLogic/schematron/schematron.xqy"; schematron:validate(fn:doc("user001.xml"), schematron:get("/userSchema.sch")) ==> <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <svrl:schematron-output title="user-validation" schemaVersion="1.0" 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="user001.xml" id="structural" name="structural"/> <svrl:fired-rule context="user"/> <svrl:active-pattern document="user001.xml" id="co-occurence" name="co-occurence"/> <svrl:fired-rule context="score"/> <svrl:failed-assert test="(@total gt 30 and ../result = 'pass') or (@total le 30 and ../result = 'fail')" location="/user[1]/score[1]"> <svrl:text>if the score is greater than 30 then the result should be 'pass' else 'fail'</svrl:text> <svrl:diagnostic-reference diagnostic="d1"> the score does not match with the result</svrl:diagnostic-reference> </svrl:failed-assert> </svrl:schematron-output>