5

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)

Ronald Wildschut
  • 417
  • 4
  • 8
  • 19

5 Answers5

6

Just install : sudo apt-get install php5-xsl

AND RESTART your APACHE Server ;)

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
Amazi
  • 61
  • 1
  • 1
3

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.

Charles
  • 50,943
  • 13
  • 104
  • 142
2

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.

jakimfett
  • 381
  • 4
  • 5
2

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)!

Paulo Victor
  • 3,814
  • 2
  • 26
  • 29
1

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.

thatidiotguy
  • 8,701
  • 13
  • 60
  • 105