在schematron中用于验证xml probatron + saxon的base-uri函数

ben*_*ser 6 java xml saxon xml-validation xml-parsing

我们使用probatronsaxon在我们的java应用程序中使用给定的sch文件验证测试xml .最近,sch文件中添加了一条新规则,例如

<let name="foo" value="base-uri()">
Run Code Online (Sandbox Code Playgroud)

并且一些规则使用该值,但是$ foo包含空字符串并且规则失败.我在哪里设置这个值?我在测试xml中添加了xml:base标签,如https://www.w3.org/TR/xmlbase/中所述,但它没有用.我是否必须在java方面设置?

编辑 (找到解决方案)我们使用probatron4j进行基于java的schematron处理:

Java源代码:

javax.xml.transform.TransformerFactory t = org.probatron.Utils.getTransformerFactory();
// create xml readers, perfor template processing, apply xslt
// as stated in the probatron4j examples
// ...

t.transform(getCandidateSource(), new StreamResult(baos));
Run Code Online (Sandbox Code Playgroud)

我们的修复包括:

Source source = new StreamSource(new FileInputStream(..

// or

Source source = new StreamSource(canditateURL.openStream()..

// depending on whether input source is file or url based

// below is the fix, we set path of file or exteral form of the url

source.setSystemId(pathOrUrl);
Run Code Online (Sandbox Code Playgroud)

最终结果:我们设置为systemid的值被设置为模式中base-uri()函数val 的返回值.

vin*_*zee 0

我们使用 probatron4j 进行基于 java 的 schematron 处理:

Java源码部分:

javax.xml.transform.TransformerFactory t = org.probatron.Utils.getTransformerFactory();
// create xml readers, perfor template processing, apply xslt
// as stated in the probatron4j examples
// ...

t.transform(getCandidateSource(), new StreamResult(baos));
Run Code Online (Sandbox Code Playgroud)

我们的修复包括:

Source source = new StreamSource(new FileInputStream(..

// or

Source source = new StreamSource(canditateURL.openStream()..

// depending on whether input source is file or url based

// below is the fix, we set path of file or exteral form of the url

source.setSystemId(pathOrUrl);
Run Code Online (Sandbox Code Playgroud)

最终结果:我们设置为systemid的值被设置base-uri()为模式中函数val的返回值。


这个答案是由 OP benchpresser在 CC BY-SA 3.0 下发布的 /sf/ask/3198497291/ 。