【发布时间】:2015-09-25 14:44:31
【问题描述】:
我正在使用 ph-sch2xslt-maven-plugin 3.0.0 将以下简单的 schematron 编译为 xslt:
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<ns prefix="m" uri="http://www.ociweb.com/movies"/>
<pattern name="all">
<rule context="m:actor">
<report test="@role=preceding-sibling::m:actor/@role"
diagnostics="duplicateActorRole">
Duplicate role!
</report>
</rule>
</pattern>
<diagnostics>
<diagnostic id="duplicateActorRole">
More than one actor plays the role<value-of select="@role"/>.
A duplicate is named<value-of select="@name"/>.
</diagnostic>
</diagnostics>
</schema>
插件将 schematron 编译成 xslt 文件。但是,尝试使用已编译的 xslt 文件会导致“未声明的命名空间前缀”错误。
使用ph-schematron 3.0.0,sn-p如下:
final ISchematronResource isr = schematronResourceXSLT.fromFile(aSchematronFile);
if (!isr.isValidSchematron ())
throw new IllegalArgumentException ("Invalid Schematron!");
产生这个:
[main] INFO com.helger.schematron.xslt.SchematronResourceXSLTCache - Compiling XSLT instance [file=/opt/temp/phschematron/schematron-model/src/main/resources/xslt/movies.xslt]
[main] ERROR com.helger.commons.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Undeclared namespace prefix {m})
[main] ERROR com.helger.commons.xml.transform.LoggingTransformErrorListener - [fatal_error] Transformation fatal error (net.sf.saxon.trans.XPathException: Undeclared namespace prefix {m})
[main] ERROR com.helger.schematron.xslt.SchematronProviderXSLTPrebuild - XSLT read/compilation error for [file=/opt/temp/phschematron/schematron-model/src/main/resources/xslt/movies.xslt]
直接使用 schematron 时,它可以工作,isValidSchematron() 返回 true:
final ISchematronResource aResPure = SchematronResourcePure.fromFile(aSchematronFile);
if (!aResPure.isValidSchematron ())
throw new IllegalArgumentException ("Invalid Schematron!");
有人能解释一下导致命名空间错误的原因吗?
【问题讨论】:
-
我拿走了你的 schematron 文件,将
<pattern name="all" >更改为<pattern id="all" >(因为不允许使用 name 属性)并使用 oXygen(抱歉,没有方便的 Maven)来生成 XSLT 1.0 和 2.0,两者工作。它在适当的位置添加了命名空间前缀m。也许是一个错误?您可以通过手动将m命名空间添加到生成的 XSLT 的根目录来修复它(使用带有此 XSLT 作为输入的后处理 XSLT 来添加它)。 -
Abel - 感谢您的反馈。我认为 ph-sch2xslt-maven-plugin 中有一个错误,因为它忽略了命名空间前缀元素。
-
好吧,since it is open source,您是否尝试过检查处理
ns节点的规则?或者将其报告为错误,或者如果您可以修复它,请提出修复建议? -
问题是你使用了错误的类。
SchematronResourceXSLT仅用于,如果您有预转换的文件。如果您有 Schematron XML,请改用SchematronResourceSCH。我只是检查当前的 4.0.1-SNAPSHOT 并且 Schematron 是有效的!
标签: xslt schematron