在PHP 5中使用Schematron验证XML

时间:2013-02-25 10:26:50

标签: php xml xslt schematron cda

我在使用schematron验证XML时遇到问题。

在我的代码中,我将XML和XSL作为DOMDocument对象加载,我尝试转换:

$domSche = new DOMDocument();
$domSche->loadXML($message);

$domXSLSche = new DOMDocument();
$domXSLSche->load("CI-SIS_StructurationCommuneCDAr2.xsl");

$xsltsche = new XSLTProcessor();
$xsltsche->importStylesheet($domXSLSche);

$XSLValid = $xsltsche->transformToXml($domSche);

但该函数返回此错误:

  

XSLTProcessor :: transformToXml():没有与之关联的样式表   对象

我不明白,从技术上讲,importStylesheet将我的XSL与XML相关联,不是吗?

如果有人想查看更多来源,则文件位于:

1 个答案:

答案 0 :(得分:1)

您使用的Schematron版本不需要XSL 2.0,但您使用的文件使用XSL 2.0功能。

PHP中的

XSLTProcessor仅支持XSL 1.0。因此,该文件中使用的某些功能不可用,导致导入失败。

由于无法导入样式表,因此转换无法运行。


错误消息

  

警告:XSLTProcessor :: transformToXml():没有与此对象关联的样式表

表示缺少样式表。不在磁盘上或内存中,而是用于转换。

那是因为它有错误而最终无法编译。

在您的情况下,您拥有的XSL文件是2.0版,但PHP仅支持1.0功能。它还使用未设置(定义)的变量。当我加载您的示例数据时,我收到以下错误:

  

警告:XSLTProcessor :: importStylesheet():编译错误:文件CI-SIS_StructurationCommuneCDAr2.xsl第13行元素样式表

这是:

            version="2.0">

并通过下一个警告解释:

  

警告:XSLTProcessor :: importStylesheet():xsl:version:仅支持1.0个功能

接下来是一个未定义的变量:

  

警告:XSLTProcessor :: importStylesheet():未定义的变量

     

警告:XSLTProcessor :: importStylesheet():编译错误:文件CI-SIS_StructurationCommuneCDAr2.xsl第4974行元素模板

    <!--RULE -->
    <xsl:template match="*[cda:templateId/@root = $templateObservationMedia]" priority="1000"
                  mode="M62">

这是$templateObservationMedia变量并导致

  

警告:XSLTProcessor :: importStylesheet():无法编译谓词

要实现这一点,您至少需要解决这些问题。由于在匹配模式中使用变量不是XSLT 1.0,因此至少需要解决这个问题。有关变量/匹配问题的扩展讨论,请参阅Multiple PHP Warnings in XSLTProcessor::importStylesheet()