一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

在 XSLTProcessor 中 registerPHPFunctions 后无法调用 php 函数解决办法

时间:2022-06-24 23:49:10 编辑:袖梨 来源:一聚教程网

但是,在 XSLT 中使用 PHP 函数时,很多人会遇到如下两种错误:

(1) Warning: XSLTProcessor::transformToXml(): xmlXPathCompiledEval: 1 objects left o
n the stack.
(2)PHP Warning: XSLTProcessor::transformToXml(): xmlXPathCompOpEval: function func
tion bound to undefined prefix php in ….

代码如下 复制代码

$xml =

bob


joe


EOB;
$xsl =
xmlns:xsl="http://www.***w3.org/1999/XSL/Transform">



EOB;
$xmldoc = DOMDocument::loadXML($xml);
$xsldoc = DOMDocument::loadXML($xsl);

$proc = new XSLTProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);
?>

其实,出现这种错误,是因为我们没有定义 PHP namespace ,只需要在

代码如下 复制代码
xmlns:xsl="http://www.***w3.org/1999/XSL/Transform">

中增加 xmlns:php="http://php*.net**/xsl" 就能解决此问题, 即

代码如下 复制代码

xmlns:xsl="http://www.***w3.org/1999/XSL/Transform"
xmlns:php="http://php*.net**/xsl">

热门栏目