Jump to content

Recommended Posts

Posted

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

Posted

:wallbash: Welcome to the Family John :dance:

 

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 :P

Posted

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. :dance:

Posted

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!

Posted
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. :dance:

 

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...