Difference between revisions of "Schematron-validation"
(Created page with " Schematron validation can be performed on XML files which need testing. For this one needs a XSL processor. We recommend [https://sourceforge.net/projects/saxon/files/Saxon-H...") |
|||
Line 18: | Line 18: | ||
-xsl:schematron\checks.xsl | -xsl:schematron\checks.xsl | ||
-o:report.xml | -o:report.xml | ||
+ | |||
+ | For the Java version of Saxon use: | ||
+ | $ java net.sf.saxon.Transform | ||
+ | -t | ||
+ | -s:test\testfile.xml | ||
+ | -xsl:schematron\checks.xsl | ||
+ | -o:report.xml | ||
+ | |||
+ | (Consult the [http://www.saxonica.com/documentation/documentation.xml Saxonica documentation] if needed.) | ||
The used schematron must be the SVRL version of Schematron. Usually this is delivered for ART projects, as a *.xsl or *_svrl.xsl version. When there is no SVRL version, this can be made. Instructions and tools can be found at [https://github.com/Schematron/schematron Github Schematron]. (SVRL is a 'xxx.sch' Schematron transformed to a 'xxx.xsl' version of it. The latter transforms a XML file to an error report.) | The used schematron must be the SVRL version of Schematron. Usually this is delivered for ART projects, as a *.xsl or *_svrl.xsl version. When there is no SVRL version, this can be made. Instructions and tools can be found at [https://github.com/Schematron/schematron Github Schematron]. (SVRL is a 'xxx.sch' Schematron transformed to a 'xxx.xsl' version of it. The latter transforms a XML file to an error report.) |
Revision as of 07:50, 11 April 2018
Schematron validation can be performed on XML files which need testing. For this one needs a XSL processor. We recommend Saxon-HE, a powerful open source application.
Usage: When the following folder structure is used (with the downloaded and extracted Saxon HE in the 'saxon' folder):
- saxon - bin - test - testfile.xml - schematron - checks.sch - checks.xsl
schematron validation can be performed with the following command (example under DOS):
$ saxon\bin\Transform -t -s:test\testfile.xml -xsl:schematron\checks.xsl -o:report.xml
For the Java version of Saxon use:
$ java net.sf.saxon.Transform -t -s:test\testfile.xml -xsl:schematron\checks.xsl -o:report.xml
(Consult the Saxonica documentation if needed.)
The used schematron must be the SVRL version of Schematron. Usually this is delivered for ART projects, as a *.xsl or *_svrl.xsl version. When there is no SVRL version, this can be made. Instructions and tools can be found at Github Schematron. (SVRL is a 'xxx.sch' Schematron transformed to a 'xxx.xsl' version of it. The latter transforms a XML file to an error report.)
This generates a report.xml file. A basic HTML view can be made with the following stylesheet: svrl2html.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SVRL report</title>
<style>
body {margin:8px;}
a[href] {color:blue;}
</style>
</head>
<body>
<h1>SVRL report</h1>
<div>Errors: <xsl:value-of select="count(.//svrl:failed-assert)"/></div>
<xsl:for-each select=".//svrl:failed-assert">
<ul>
<li><b>Text: <xsl:value-of select="svrl:text"/></b></li>
<li>Test: <xsl:value-of select="@test"/></li>
<li>See: <xsl:value-of select="@see"/></li>
<li>Location: <xsl:value-of select="@location"/></li>
</ul>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
This transform again can be done with Saxon:
$ saxon\bin\Transform -t -s:report.xml -xsl:svrl2html.xsl -o:report.html