How to perform schematron validation using Saxon java library command line tool?
Asked Answered
L

2

6

Very basic question- I've a xml file and I want to validate it against a schematron file. How do I do it using Saxon command line?

As per commandline reference I don't see any option to specify schematron file.

Lavine answered 31/3, 2012 at 11:42 Comment(0)
L
1

After doing a lot of research, it seems that it isn't really possible. We have to first generate xsl document and then use it to perform validation.

Lavine answered 31/3, 2012 at 13:39 Comment(1)
Michael Kay himself says that “Saxon itself does not have any schematron capability.” See https://mcmap.net/q/1773294/-validating-xml-file-against-schematron-sch-in-net-saxonFabri
R
9

Expanding on the previous answer because I needed to do this and it didn't give enough info (and since my script is already doing a dozen XSL transforms - what's four more?)

Based on this website an XML file can be validated against a schematron through a series of XSL transformations. Since I also needed information on how to combine with saxon - here are the modifications for saxon, on a windows box, with a catalog file.

Here is how I run an XSLT through the saxon command line on my computer (where FilePath is system dependent):

java -cp "C:\FilePath\saxon9ee.jar;C:\FilePath\resolver.jar";. net.sf.saxon.Transform -s:inputFile.xml  -o:outputFile.xml  -xsl:C:\FilePath\transform.xsl -catalog:"C:\FilePath\catalog.xml" 

The big thing to point out here is that when you are using a catalog file with Saxon you have to point it back to the resolver.jar file.

So with

XSLT = java -cp "C:\FilePath\saxon9ee.jar;C:\FilePath\resolver.jar";. net.sf.saxon.Transform -catalog:"C:\FilePath\catalog.xml"

Then the info from the website makes sense (having found the necessary xsl files in oXygen):

 XSLT -input=xxx.sch  -output=xxx1.sch  -stylesheet=iso_dsdl_include.xsl
 XSLT -input=xxx1.sch  -output=xxx2.sch  -stylesheet=iso_abstract_expand.xsl
 XSLT -input=xxx2.sch  -output=xxx.xsl  -stylesheet=iso_svrl.xsl
 XSLT -input=document.xml  -output=xxx-document.svrl  -stylesheet=xxx.xsl

You are taking the schematron file, running it through three transforms to get out an xsl file that you then run on the original xml document. This actually makes it relatively easy to script.

The last command has never actually populated an output file for me. Since it runs fine without one and dumps the messages to STOUT, I just leave it off and collect the results from there.

Sorry for going into more detail than is probably necessary, but I wish I'd had this all to begin with.

Rhizo answered 5/5, 2014 at 21:52 Comment(0)
L
1

After doing a lot of research, it seems that it isn't really possible. We have to first generate xsl document and then use it to perform validation.

Lavine answered 31/3, 2012 at 13:39 Comment(1)
Michael Kay himself says that “Saxon itself does not have any schematron capability.” See https://mcmap.net/q/1773294/-validating-xml-file-against-schematron-sch-in-net-saxonFabri

© 2022 - 2024 — McMap. All rights reserved.