XSLTProcessor issues w/php 5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mummra1
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:50 am

XSLTProcessor issues w/php 5

Post by mummra1 »

Hello all,
Hello all,
I'm using php 5 to try and transform xml. I call a function such as;

Code: Select all

transformXML('xmldoc.xml','xslstylesheet.xsl');




...which references

Code: Select all

function transformXML($filename,$stylesheet)  {
        
        $xml = new DOMDocument;
        $xml->load($filename);
        
        $xsl = new DOMdocument;
        $xsl->load($stylesheet);
        
        
        $xslt = new XSLTProcessor;
        $xslt->importStylesheet($xsl);
        
        $results = $xslt->transformToURI($xml,'file:///temp/test.html');
           echo $results;


       
      }//end function transformXML



The problem is that there is no output. I've tried other methods of the XSLTProcessor to output xhtml, all of which I can't get to work. All I really want to do is create and save an xhtml file from my xml. I've checked my apache (2.2) error log and I'm not getting any errors on the function. Has anyone had success outputting xhtml files with XSLTProcessor? Thanks!
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

$results = $xslt->transformToURI($xml,'file:///temp/test.html');
echo $results;
should be

Code: Select all

$results = $xslt->transformToXML($xml);
echo $results;
if you want output.

To save to a file use something like:

Code: Select all

$results = $xslt->transformToXML($xml);
file_put_contents('temp/test.html', $results);
User avatar
mummra1
Forum Newbie
Posts: 6
Joined: Thu Aug 17, 2006 7:50 am

Post by mummra1 »

thanks a million....I was trying to use the $dom->save method, but to no avail :oops:

Cheers!
Post Reply