2013-02-25 76 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()