“XSLTProcessor”类未找到

发布于 2024-12-29 09:35:32 字数 432 浏览 3 评论 0原文

我正在尝试使用 XSLT 将 XML 文件转换为 HTML 输出。

我的代码如下:

<?php

$xml = new DOMDocument;
$xml->load('file.xml');

$xsl = new DOMDocument;
$xsl->load('file.xsl');

$proc = new XSLTProcessor;

$proc->importStyleSheet($xsl);

echo $proc->transformToXML($xml);

?> 

但我收到错误:致命错误:找不到类“XSLTProcessor”

我知道这与事实有关dat xsltprocessor 在我的服务器上没有用 PHP 编译...但我似乎找不到启用它的方法。 (我不控制服务器,但我的托管可以)

I'm trying to transform a XML file to a HTML output with XSLT..

My code is as following:

<?php

$xml = new DOMDocument;
$xml->load('file.xml');

$xsl = new DOMDocument;
$xsl->load('file.xsl');

$proc = new XSLTProcessor;

$proc->importStyleSheet($xsl);

echo $proc->transformToXML($xml);

?> 

But I'm getting the error: Fatal error: Class 'XSLTProcessor' not found

I know this has something to do with the fact dat the xsltprocessor is not compiled with PHP on my server... But I can't seem to find a way to enable it. (I do not control the server, but my hosting does)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

煞人兵器 2025-01-05 09:35:32

只需安装:sudo apt-get install php5-xsl

并重新启动您的 APACHE 服务器;)

Just install : sudo apt-get install php5-xsl

AND RESTART your APACHE Server ;)

末が日狂欢 2025-01-05 09:35:32

我不控制服务器

PHP XSL 扩展 可以 仅由系统管理员安装和启用。

虽然它默认编译,但当服务器使用预打包版本的 PHP 时,通常默认情况下不会安装。如果您使用的是 *nix,请要求您的主机安装 php-xml 软件包。如果您在 Windows 上托管,它会变得更加复杂,因为它需要找到正确的 .dll 文件(可能包含也可能不包含在官方发行版中)并编辑 php.ini。

I do not control the server

The PHP XSL extension can only be installed and enabled by the sysadmin.

While it's compiled by default, it is usually not installed by default when the server is using a pre-packaged version of PHP. Ask your host to install the php-xml package if you're on a *nix. If you're hosting on Windows, it becomes a bit more involved, as it requires finding the right .dll file (which may or may not be included in the official distribution) and editing php.ini.

假装不在乎 2025-01-05 09:35:32

对于 apache2/php5,您需要安装并启用 php5-xsl 扩展。

http://php.net/manual/en/book.xsl.php提供有关如何安装 xsl 扩展的信息。要启用此功能,请将“extension=php_xsl.so”行放入 php.ini 文件中。

如果仍然无法正常工作,请在服务器上创建一个包含“”行的新 .php 文件。加载您刚刚创建的文件,然后搜索“xsl”以查看扩展名是否确实正在加载。

With apache2/php5, you need the php5-xsl extension installed and enabled.

http://php.net/manual/en/book.xsl.php gives information on how to install the xsl extension. To enable, put the line "extension=php_xsl.so" in your php.ini file.

If it's still not working, create a new .php file on your server containing the line "". Load the file you just created, and search for "xsl" to see if the extension is actually being loaded.

静赏你的温柔 2025-01-05 09:35:32

必须安装 XLS 扩展。

根据我的上下文我的解决方案。

我正在使用一个包含 ubuntu 基础的 docker 容器并使用 php-fpm (即,如果您已经在其中使用 linux ubuntu)。

在我的上下文中安装此扩展的步骤是:

首先在 Linux 存储库上搜索 xsl 扩展

sudo apt-cache search xsl

我最终找到了 php5-xsl,所以它只是安装

sudo apt-get install php5-xsl

说明安装过程中setup配置已经添加了,如果没有出现,就自己搞一下

sudo vim /etc/php5/mods-available/xsl.ini

插入以下内容:
extension=xsl.so

(显然路径是根据您的 php 配置设置,但我的示例是默认配置)

重新启动 php fpm 并完成(sudo service php5-fpm restart)!

Its necessary install the XLS extension.

My solution by my context.

I'm using one docker container contain ubuntu base and using php-fpm (ie if you simply already use linux ubuntu in the same).

The steps to install this extension in my context were:

First search xsl extension on linux repository

sudo apt-cache search xsl

I ended up finding the php5-xsl, so it was only install

sudo apt-get install php5-xsl

that the installation process the setup configuration is already added, if does not happen, just make yourself

sudo vim /etc/php5/mods-available/xsl.ini

insert this content:
extension=xsl.so

(obviously the paths are according to your php configuration settings, but my example is the default configuration)

Restart you php fpm and done (sudo service php5-fpm restart)!

最好是你 2025-01-05 09:35:32

如果您的 php 环境在 Linux 上,您可以使用以下命令启用 php 扩展:

yum install php-xml

如果是 Windows 系统,您可以进入 php.ini 配置文件并取消注释 php_xml.dll 扩展。

希望有帮助。顺便说一句,快速的谷歌搜索可以在未来回答类似的问题。

If your php environment is on linux you can probably enable the php extension by using this command:

yum install php-xml

If it is a windows system, you can go into your php.ini config file and uncomment the php_xml.dll extension.

Hope that helps. A quick google search can answer questions like these in the future btw.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文