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

为君一笑 提交于 2019-12-06 01:56:58

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!