在PHP 5中使用Schematron验证XML [英] Validate XML with Schematron in PHP 5
问题描述
我在使用 schematron 验证XML时遇到问题.
I have a problem with validating XML with schematron.
在我的代码中,我将XML和XSL加载为DOMDocument对象,然后尝试进行转换:
In my code I load the XML and XSL as DOMDocument objects and I try to transform:
$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);
但是该函数返回此错误:
But the function returns this error:
XSLTProcessor :: transformToXml():没有与此相关的样式表 对象
XSLTProcessor::transformToXml(): No stylesheet associated to this object
从技术上讲,我不理解importStylesheet将我的XSL与XML关联,不是吗?
I don't understand, technically, the importStylesheet associates my XSL to the XML, no?
如果有人想查看更多来源,则文件位于:
If someone wants to look at more sources, files are at :
- $message
- CI-SIS_StructurationCommuneCDAr2.xsl
推荐答案
您使用的Schematron版本不需要XSL 2.0,但是您使用的文件使用了XSL 2.0功能.
The Schematron version you make use of does not require XSL 2.0 however the file you have makes use of XSL 2.0 features.
XSLTProcessor
仅支持XSL 1.0.因此,该文件中使用的某些功能不可用,并导致导入失败.
XSLTProcessor
in PHP supports XSL 1.0 only. Some of the features used in that file are therefore not available and make the import fail.
由于无法导入样式表,因此转换无法运行.
As the stylesheet could not be imported, the transformation can not run.
错误消息
警告:XSLTProcessor :: transformToXml():没有与此对象关联的样式表
Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object
表示样式表丢失.不在磁盘或内存中,而是用于转换.
means that the stylesheet is missing. Not on disk or in memory, but for the transformation.
那是因为它有错误,最终无法编译.
That is because it has errors and finally could not compile.
在您的情况下,您拥有的XSL文件的版本为2.0,但PHP仅支持1.0的功能.它还利用未设置(定义)的变量.当我加载示例数据时,出现以下错误:
In your case the XSL file you have is of version 2.0 but PHP only supports 1.0 features. Also it makes use of variables that are not set (defined). When I load your example data I get the following errors:
警告:XSLTProcessor :: importStylesheet():编译错误:文件CI-SIS_StructurationCommuneCDAr2.xsl第13行元素样式表
Warning: XSLTProcessor::importStylesheet(): compilation error: file CI-SIS_StructurationCommuneCDAr2.xsl line 13 element stylesheet
哪个是:
version="2.0">
,并通过下一个警告进行解释:
and explained by the next warning:
警告:XSLTProcessor :: importStylesheet():xsl:version:仅支持1.0功能
Warning: XSLTProcessor::importStylesheet(): xsl:version: only 1.0 features are supported
下一个是未定义的变量:
Next is an undefined variable:
警告:XSLTProcessor :: importStylesheet():未定义变量
Warning: XSLTProcessor::importStylesheet(): Undefined variable
警告:XSLTProcessor :: importStylesheet():编译错误:文件CI-SIS_StructurationCommuneCDAr2.xsl第4974行元素模板
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
变量并指向
警告:XSLTProcessor :: importStylesheet():无法编译谓词
Warning: XSLTProcessor::importStylesheet(): Failed to compile predicate
要使其正常工作,您至少需要解决这些问题.由于在匹配模式中使用的变量不是XSLT 1.0,因此至少需要解决该问题.有关变量/匹配问题的扩展讨论,请参见 XSLTProcessor :: importStylesheet()中的多个PHP警告.
To get this working you would need at least fix these problems. As using the variable inside the match pattern is not XSLT 1.0 you need to work around that at least. See Multiple PHP Warnings in XSLTProcessor::importStylesheet() for an extended discussion of the variable/match issue.
这篇关于在PHP 5中使用Schematron验证XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!