如何在 PHP 5 中启用 XSLT 功能?

2024-01-11

我想使用 xslt 将 xml 文件打印为 HTML 嵌套列表,据我所知代码是正确的,但是我收到此错误

致命错误:调用未定义的函数 xslt_create()

我认为这意味着 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 contents\n<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); 

    ?>

提前致谢!


根据您的 Linux 发行版,您可能只需安装 php5-xsl 模块,将“extension=php_xsl.so”行添加到 php.ini 文件中,然后重新启动 apache2 服务器即可。

这在 Ubuntu 11.10 上对我有用。您可以在命令行中输入“sudo apt-get install php5-xsl”来安装php5-xml。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 PHP 5 中启用 XSLT 功能? 的相关文章