Xslt Support

liunx

Guest
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 (<!-- m --><a class="postlink" href="http://www.linuxwebdevnews.com/articles/php-xslt-param/">http://www.linuxwebdevnews.com/articles/php-xslt-param/</a><!-- m -->).<br /><br />Yet when I load them up on my site and request the *.php page, this is the response I get:<br /><br />Fatal error: Call to undefined function: xslt_run() in /home/.../transform.php on line 12<br /><br />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.<br /><br />Any help would be greatly appreciated!<br /><br />TIA,<br />John<br /><br />test url: <a href="http://dev.johndwells.com/transform.php" target="_blank">http://dev.johndwells.com/transform.php</a><!--content-->
<img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/kicking.gif" style="vertical-align:middle" emoid=":dance:" border="0" alt="kicking.gif" /> Welcome to the Family John <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/kicking.gif" style="vertical-align:middle" emoid=":dance:" border="0" alt="kicking.gif" /> <br /><br />and your new home!<br /><br />I can't help you<br />but I will move this to the scripting forum<br />for better exposure.<br /><br />We really are like family here.<br />So if you need anything,<br />just ask your new family!<br />We love to help <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Hi John,<br /><br />The XSLT processing should work correctly. The problem is the source of your example. The article you are working off of is from 2001. <b>xslt_run()</b> has not been a supported function in PHP since version 4.1.0 (we are running 4.3.10 currently).<br /><br />You can find a list of the currently supported XSLT functions here: <a href="http://www.php.net/xslt" target="_blank">http://www.php.net/xslt</a><br /><br />Good luck with your learning. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
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!<!--content-->
Welcome to the forums John! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Welcome to the forums John! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/cool.gif" style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /><!--content-->
<!--QuoteBegin-TCH-MikeJ+Mar 11 2005, 03:48 AM--><div class='quotetop'>QUOTE(TCH-MikeJ @ Mar 11 2005, 03:48 AM)</div><div class='quotemain'><!--QuoteEBegin-->The XSLT processing should work correctly.  The problem is the source of your example.  The article you are working off of is from 2001.  <b>xslt_run()</b> has not been a supported function in PHP since version 4.1.0 (we are running 4.3.10 currently).<br /><br />You can find a list of the currently supported XSLT functions here: <a href="http://www.php.net/xslt" target="_blank">http://www.php.net/xslt</a><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />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...<br /><br />Ah, but I finally figured everything out just now! Agh! In case any other TCHers are curious, here's what finally worked for me:<br /><br /><?php<br /><br />// Initiate the Sablotron XSLT handler<br />$hXSLT = xslt_create();<br /><br />// Pass XML and XSL data as strings into an array<br />$aArguments = array(<br />'sXML' => file_get_contents("transform.xml"),<br />'sXSL' => file_get_contents("transform.xsl"));<br /><br />// Pass xslt_process the transform handler, the xml and xsl strings (as arguments),<br />// the $sTransformResult container string, and the $aArguments array<br />$sTransformResult = xslt_process($hXSLT, 'arg:sXML', 'arg:sXSL', NULL, $aArguments);<br /><br />// Print out the transformed data<br />echo $sTransformResult;<br /><br />// Free up the XSLT handler resource<br />xslt_free($hXSLT);<br />?><br /><br />On <a href="http://www.php.net/manual/en/function.xslt-process.php" target="_blank">http://www.php.net/manual/en/function.xslt-process.php</a> 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. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/dry.gif" style="vertical-align:middle" emoid="<_<" border="0" alt="dry.gif" /> <br /><br />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.<br /><br />Thanks for the warm welcome to the family! You guys are the best. . .<br />-John<!--content-->
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!)<!--content-->
Congrats John! Glad you got it working and thanks for the update. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
 
Back
Top