johndwells Posted March 11, 2005 Posted March 11, 2005 I'm trying to learn and practice php's abilities to transform xml via xslt, and so I've downloaded a simple set of files to begin my journey (http://www.linuxwebdevnews.com/articles/php-xslt-param/). Yet when I load them up on my site and request the *.php page, this is the response I get: Fatal error: Call to undefined function: xslt_run() in /home/.../transform.php on line 12 When I run phpinfo() I see that php is configured to run the Sablotron extension, so I'm assuming everything would work. . . Of course I'm fishing blind here since I have no experience with it yet. Any help would be greatly appreciated! TIA, John test url: http://dev.johndwells.com/transform.php Quote
TCH-Don Posted March 11, 2005 Posted March 11, 2005 Welcome to the Family John and your new home! I can't help you but I will move this to the scripting forum for better exposure. We really are like family here. So if you need anything, just ask your new family! We love to help Quote
MikeJ Posted March 11, 2005 Posted March 11, 2005 Hi John, The XSLT processing should work correctly. The problem is the source of your example. The article you are working off of is from 2001. xslt_run() has not been a supported function in PHP since version 4.1.0 (we are running 4.3.10 currently). You can find a list of the currently supported XSLT functions here: http://www.php.net/xslt Good luck with your learning. Quote
stevevan Posted March 11, 2005 Posted March 11, 2005 Welcome to the forums John. Learning something new is always a good thing! Way to go! And as Don said, there are many people here willing to help you out! Quote
johndwells Posted March 11, 2005 Author Posted March 11, 2005 The XSLT processing should work correctly. The problem is the source of your example. The article you are working off of is from 2001. xslt_run() has not been a supported function in PHP since version 4.1.0 (we are running 4.3.10 currently). You can find a list of the currently supported XSLT functions here: http://www.php.net/xslt Yep, hours after I posted my initial inquiry, I had finally figured that out. . . so I continued testing with xslt_process, and have still encountered problems...and again I think it's the problem of where everyone in the www is copy-and-pasting the same script. So I can only find the methods I'm unsuccessfully using, and neither Sablotron or PHP.net have any hints... Ah, but I finally figured everything out just now! Agh! In case any other TCHers are curious, here's what finally worked for me: <?php // Initiate the Sablotron XSLT handler $hXSLT = xslt_create(); // Pass XML and XSL data as strings into an array $aArguments = array( 'sXML' => file_get_contents("transform.xml"), 'sXSL' => file_get_contents("transform.xsl")); // Pass xslt_process the transform handler, the xml and xsl strings (as arguments), // the $sTransformResult container string, and the $aArguments array $sTransformResult = xslt_process($hXSLT, 'arg:sXML', 'arg:sXSL', NULL, $aArguments); // Print out the transformed data echo $sTransformResult; // Free up the XSLT handler resource xslt_free($hXSLT); ?> On http://www.php.net/manual/en/function.xslt-process.php they list 4 examples, but with current versions of PHP only examples 3 and 4 are correct. xslt_process can no longer accept the filenames of your xml and xslt files as arguments; you first have to set them to strings. AND you can't merely pass the strings to the function; you must set them into arrays, and pass both the array ($aArguments) and it's pair indices ('arg:sXML' and 'arg:sXSL'). The NULL is where $sTransformResult COULD go if you were to just call the function without passing the results to a string, but this doesn't work either. Boy that was a struggle to get to the solution! But the benefits are great -- instead of echoing the results to the screen, I can save them down as a static (X)HTML file. Thanks for the warm welcome to the family! You guys are the best. . . -John Quote
stevevan Posted March 11, 2005 Posted March 11, 2005 John: Glad you got it figured out! Thanks for posting your results, too. I'm sure it will help someone somewhere with a similar issue. (I know I learned something here!) Quote
TCH-Bruce Posted March 11, 2005 Posted March 11, 2005 Congrats John! Glad you got it working and thanks for the update. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.