如何在PHP 5中启用XSLT功能?
我想使用xslt将xml文件打印为
HTML嵌套列表,据我所知,代码是正确的,但是我收到此错误
我认为这意味着xslt功能尚未启用.如何在PHP中启用这些功能?我需要包含一个php文件(就像Javascript库的工作方式)还是更复杂的东西?我主持了MediaTemple. 这是我正在使用的PHP代码: <?php // Allocate a new XSLT processor $xh = xslt_create(); // Process the document,returning the result into the $result variable $result = xslt_process($xh,'armstrong.xml','familyToNestedList.xsl'); if ($result) { print "SUCCESS,sample.xml was transformed by sample.xsl into the $result"; print " variable,the $result variable has the following contentsn<br>n"; print "<pre>n"; print $result; print "</pre>n"; } else { print "Sorry,sample.xml could not be transformed by sample.xsl into"; print " the $result variable the reason is that " . xslt_error($xh) . print " and the error code is " . xslt_errno($xh); } xslt_free($xh); ?> 提前致谢!
您需要
compile PHP并支持它,并确保拥有所有必需的依赖项.请参阅
PHP Manual for XSLT中的相应章节.
从第Requirements章开始
从第Installation章开始
recommended extension for using XSL transformations with PHP5 is XSL.如果你需要做的就是转换两个文档,如你的例子中所示,请考虑PHP手册中的这个例子: $xml = new DOMDocument; $xml->load('collection.xml'); $xsl = new DOMDocument; $xsl->load('collection.xsl'); // Configure the transformer $proc = new XSLTProcessor; $proc->importStyleSheet($xsl); // attach the xsl rules echo $proc->transformToXML($xml); transformToXML方法将返回已转换的文档或FALSE,因此您可以保留代码中的if / else.无论如何,升级代码应该是微不足道的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |