Hey everyone,
i've been having some trouble getting XML and XSL to be transformed when I am using "dynamic" XML from a MySQL database. I get a query from the database, put it into a variable $xml and then try to use that with an XSL file to transform the $xml data into a result that is outputted to a browser. But when I run this, nothing happens--I just get a blank screen. here's the code... and I have been trying to find out how to do this by reading the examples on this page
<?php
//
// DB Connect stuff here
// ...
//
$query = "select * from story where sid < 2";
$result = mysql_query($query, $dbi);
$numfields = mysql_num_fields($result);
$numrows = mysql_num_rows($result);
echo "total results: $numrows <br /><br /><br />";
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><br /><br />";
while($row = mysql_fetch_object($result)) {
$xml .= "<entry><br />";
for ($j=0; $j < $numfields; $j++) {
$tag = mysql_field_name($result, $j);
$xml .= "<$tag>" . strip_tags($row->$tag) . "</$tag><br />";
}
$xml .= "</entry>";
$xml .= "<br /><br />";
}
$arguments = array(
'/_xml' => $xml
);
//create instance of xslt parser
$xh = xslt_create();
// Process the document
$result = xslt_process($xh, 'arg:/_xml', 'sqlxsl.xsl', NULL, $arguments);
if ($result) {
echo "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
echo " variable, the \$result variable has the following contents\n<br />\n";
echo "<pre>\n";
echo $result;
echo "</pre>\n";
} else {
echo "Sorry, sample.xml could not be transformed by sample.xsl into";
echo " the \$result variable the reason is that " . xslt_error($xh) .
echo " and the error code is " . xslt_errno($xh);
}
xslt_free($xh);
?>