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!
Hope someone can help with this...
Am trying to generate XSL in PHP and use it to transform XML, also generated dynamically. Below is a summary of code...
//construct xsl and save to DOM
$xsldoc = new DomDocument('1.0');
$xslroot = $xsldoc->createElement('xsl:stylesheet');
$xslroot = $xsldoc->appendChild($xslroot);
etc etc
...$xsldoc->saveXML();
//construct xml and save to DOM
$doc = new DomDocument('1.0');
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
etc etc
...$xml_string = $doc->saveXML();
//transform. this is where i have problems. 2nd line wont work
$xslt = new xsltProcessor;
$xslt->importStyleSheet(DomDocument::load($xsldoc));
echo $xslt->transformToXML(DomDocument::loadXML($xml_string));
<?php
require_once('error.php');
require_once('mysql.php');
require_once('rstoxml.php');
require_once('transform.php');
require_once('output.php');
$query = "SELECT m.message_id AS message_id, m.title AS title, m.content AS content, m.datetime AS datetime, IF(ISNULL(comment_id), 0, COUNT(*)) AS count FROM message AS m LEFT JOIN comment AS c USING (message_id) GROUP BY m.message_id ORDER BY m.datetime DESC LIMIT 5";
$result = mysql_query($query) or trigger_error(mysql_error(), E_USER_ERROR);
$xml = rstoxml($result);
$xsl = file_get_contents('xsl/index.xsl');
$xhtml = transform($xml, $xsl);
output($xhtml);
?>
sorry.. i should be more specific. The problem is that I need to generate the XSL dynamically, not from a file, and the $xslt->importStyleSheet(DomDocument::load) code is expecting a file, not an object. i get these errors:
Warning: I/O warning : failed to load external entity "3%AA%E7ws%FA%12" in C:\PHP\classes4\dataXML.php on line 66
Warning: importStylesheet() expects parameter 1 to be object, boolean given in C:\PHP\classes4\dataXML.php on line 66
Warning: XSLTProcessor::transformToXml() [function.transformToXml]: No stylesheet associated to this object in C:\PHP\classes4\dataXML.php on line 67