2013-02-25 37 views
2

我在验证XML时遇到问题schematron在PHP 5中使用Schematron验证XML

在我的代码加载XML和XSL为DOM文档对象和我尝试变换:

$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(): No stylesheet associated to this object

我不明白,在技术上,importStylesheet将我的XSL关联到XML,不是吗?

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

+0

查看类似:http://stackoverflow.com/q/4822914/287948 – 2014-07-28 08:09:14

回答

1

的Schematron的版本,您使用的,不需要XSL 2.0然而该文件,你已经使用了XSL 2.0功能。

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

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


该错误消息

Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object

意味着该样式表是丢失。不是在磁盘或内存中,而是为了转换。

这是因为它有错误,最后无法编译。

就你而言,你拥有的XSL文件是2.0版本,但PHP仅支持1.0特性。它也使用未设置(定义)的变量。当我打开你的榜样的数据我收到以下错误:

Warning: XSLTProcessor::importStylesheet(): compilation error: file CI-SIS_StructurationCommuneCDAr2.xsl line 13 element stylesheet

那就是:

  version="2.0"> 

,并通过下一个警告解释说:

Warning: XSLTProcessor::importStylesheet(): xsl:version: only 1.0 features are supported

接下来是未定义的变量:

Warning: XSLTProcessor::importStylesheet(): Undefined variable

Warning: XSLTProcessor::importStylesheet(): compilation error: file CI-SIS_StructurationCommuneCDAr2.xsl line 4974 element template

其中是

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

这是$templateObservationMedia变量并导致

Warning: XSLTProcessor::importStylesheet(): Failed to compile predicate

为了得到这个工作,你至少需要解决这些问题。由于在匹配模式中使用变量不是XSLT 1.0,所以至少需要解决该问题。有关变量/匹配问题的扩展讨论,请参见Multiple PHP Warnings in XSLTProcessor::importStylesheet()