Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enable XSLT functions in PHP 5?

I'm wanting to print an xml file out as an HTML nested list using xslt, and as far as I know the code is correct, however I'm getting this error

Fatal error: Call to undefined function xslt_create()

Which I presume means the xslt functions havn't been enabled. How do I enable these functions within PHP? Is there a php file I need to include (like the way Javascript libraries work) or is it something more complicated? I'm hosted with MediaTemple.

Here's the php code I'm using:

        <?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); 

    ?>

Thanks in advance!

like image 208
Chris Armstrong Avatar asked Dec 15 '10 14:12

Chris Armstrong


1 Answers

Depending on your distro of linux, you may be able to just install the php5-xsl module, add the line "extension=php_xsl.so" to your php.ini file, and restart your apache2 server.

This worked for me on Ubuntu 11.10. You can input "sudo apt-get install php5-xsl" into the command line to install php5-xml.

like image 171
jakimfett Avatar answered Sep 18 '22 19:09

jakimfett