Jump to content

Execute XSLT with PHP


boen_robot
 Share

Recommended Posts

W3Shools' XSLT on the server example demonstrates how XSLT transformations could be executed with ASP, so the user could see the final XHTML output. Could anyone offer me that same equivalent in PHP please? What I need is only to execute it. No funny business within the file (in other words... I'm not asking for anything special)... just that. Do I need something special on the server (I hope not)? Are there differences between PHP4 and PHP5 in this matter?

Link to comment
Share on other sites

  • 1 month later...

According to the XSL functions description on the PHP home site, the extension is built in, but it requres the libxslt to be installed and to add the argument --with-xsl[=DIR] to my configure line. I downloaded the library, but how do I install it? And where the heck is that configuration line? Is it somewhere in the php.ini file? If so, where?

Link to comment
Share on other sites

According to the XSL functions description on the PHP home site, the extension is built in, but it requres the libxslt to be installed and to add the argument --with-xsl[=DIR] to my configure line. I downloaded the library, but how do I install it? And where the heck is that configuration line? Is it somewhere in the php.ini file? If so, where?

Configuration options like that are compiler options, you include that when compiling PHP from source code. I believe that the zip package of PHP available on php.net is compiled with support for all of the extensions on php.net, but the Windows installer is not. If you already have a binary of the PHP engine, you don't use those configuration options.Similarly, you only need to have the libxslt library available at compile time, not runtime. Libraries like that are compiled into the PHP binary. If you go to the libxslt site, you will see that it is called the The XSLT C library, it is for the C language and is linked to during compilation. That is why the zip distribution of PHP is so much larger than the Windows installer, because all of those libraries have been included. If you are running off the zip binary (or off a commercial webserver), then you probably already have support. If this code executes, you have support:
$xsl = new XSLTProcessor();

Also, try this for performing your transformation:

$xsl = new XSLTProcessor();$doc->load($xsl_filename);$xsl->importStyleSheet($doc);$doc->load($xml_filename);echo $xsl->transformToXML($doc);

More help is on the php.net pages for XSL functions, although there is no versioning information. Due to the fact that this is an object-oriented extension, it might only work in PHP5.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...