ph schematron:使用ph-sch2xslt-maven-plugin将schematron编译为xslt后出现名称空间前缀错误

ph schematron:使用ph-sch2xslt-maven-plugin将schematron编译为xslt后出现名称空间前缀错误,xslt,schematron,Xslt,Schematron,我正在使用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"> &

我正在使用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>
产生以下结果:

[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!");

有人能解释一下导致名称空间错误的原因吗?

这是ph schematron的一个错误,已在4.0.1中修复,于2016年7月5日发布。

我获取了您的schematron文件,将
更改为
(因为不允许使用name属性),并使用oXygen(抱歉,没有Maven手边)生成XSLT 1.0和2.0,两者都起作用了。它在适当的位置添加了名称空间前缀
m
。也许是虫子?您可以通过手动将
m
名称空间添加到生成的XSLT的根中来修复它(使用带有此XSLT的后处理XSLT作为输入来添加它)。Abel-感谢您的反馈。我认为ph-sch2xslt-maven-plugin中有一个bug,因为它忽略了名称空间前缀元素。那么,您是否尝试过检查it处理
ns
节点的规则?或者将其报告为bug,或者如果您可以修复它,则建议修复?问题在于您使用了错误的类
SchematronResourceXSLT
仅在具有预转换文件的情况下使用。如果您有SchematronXML,请改用
SchematronResourceSCH
。我只是检查了当前的4.0.1快照,Schematron是有效的!感谢你的帮助,Bae:)
final ISchematronResource aResPure = SchematronResourcePure.fromFile(aSchematronFile);
if (!aResPure.isValidSchematron ())
    throw new IllegalArgumentException ("Invalid Schematron!");