0
我正在嘗試使用saxon進行schematron驗證。首先,我想將.sch文件編譯爲.xsl文件。後來,我想用首先生成的.xsl文件來驗證.xml文件。在java代碼中使用saxon困難.sch轉換爲.xsl
我發現像下面這樣的撒克遜命令行用法。我成功地使用了它們。 但我需要使用java代碼進行這些操作。 我嘗試了下面的一些代碼,但我沒有猜到如何將sch擴展文件作爲參數(edefter_yevmiye.sch)和iso_svrl_for_xslt2.xsl放入代碼中。 我搜索了互聯網,但我沒有找到足夠的信息。 是否有將.sch轉換爲.xsl的示例java代碼,或者可以引導我嗎?
我的Java代碼
**Compiling .sch to .xsl**
net.sf.saxon.s9api.Processor processor1 = new net.sf.saxon.s9api.Processor(false);
net.sf.saxon.s9api.XsltCompiler xsltCompiler1 = processor1.newXsltCompiler();
xsltCompiler1.setXsltLanguageVersion("2.0");
xsltCompiler1.setSchemaAware(true);
net.sf.saxon.s9api.XsltExecutable xsltExecutable1 = xsltCompiler1.compile(new StreamSource(new FileInputStream(new File("File1.xsl"))));
net.sf.saxon.s9api.XsltTransformer xsltTransformer1 = xsltExecutable1.load();
xsltTransformer1.setSource(new StreamSource(new FileInputStream(new
File("File2.sch"))));
**Validation**
net.sf.saxon.s9api.Processor processor2 = new net.sf.saxon.s9api.Processor(false);
net.sf.saxon.s9api.XsltCompiler xsltCompiler2 = processor2.newXsltCompiler();
xsltCompiler2.setXsltLanguageVersion("2.0");
xsltCompiler2.setSchemaAware(true);
net.sf.saxon.s9api.XsltExecutable xsltExecutable2 = xsltCompiler2.compile(new StreamSource(new
FileInputStream(new File(「File1.xslt"))));
net.sf.saxon.s9api.XsltTransformer xsltTransformer2 = xsltExecutable2.load();
xsltTransformer2.setSource(new StreamSource(new FileInputStream(new
File("src.xml"))));
net.sf.saxon.s9api.Destination dest2 = new Serializer(System.out);
xsltTransformer2.setDestination(dest2);
xsltTransformer1.setDestination(xsltTransformer2);
xsltTransformer1.transform();
命令行模式
編譯:
java -jar saxon9he.jar -o:output.xsl -s:some.sch iso_svrl_for_xslt2.xsl
驗證:
java -jar saxon9he.jar -o:warnings.xml -s:some.xml output.xsl
在薩克森的「resources」文件中有很多使用s9api接口的例子,稱爲samples/S9APIExamples.java,您可以從SourceForge或Saxonica站點下載該文件。你基本上已經明白了,如果失敗並且您不瞭解失敗,請告訴我們失敗的原因。 – 2014-10-03 14:33:25