我在使用 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(): No stylesheet associated to this object
从技术上讲,我不明白 importStylesheet 将我的 XSL 关联到 XML,不是吗?
如果有人想查看更多资源,文件位于:
最佳答案
您使用的 Schematron 版本不需要 XSL 2.0,但是您拥有的文件使用了 XSL 2.0 功能。
PHP 中的XSLTProcessor
仅支持 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
接下来是一个 undefined variable :
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()。
关于php - 在 PHP 5 中使用 Schematron 验证 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15064814/