Page 1 of 1

XSLTProcessor issues w/php 5

Posted: Fri Dec 15, 2006 11:08 am
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!

Posted: Fri Dec 15, 2006 11:16 am
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);

Posted: Fri Dec 15, 2006 11:28 am
by mummra1
thanks a million....I was trying to use the $dom->save method, but to no avail :oops:

Cheers!