note 26746 added to function.xslt-process
| From: | sanj at wiredesign dot com | Date: | Mon, 11 Nov 2002 17:34:55 +0000 |
| Subject: | note 26746 added to function.xslt-process | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39303@lists.php.net to get a copy of this message | ||
Okay, now this is a neat function once you play around with it
bit...we're basically using it in two ways...one to preview data
from a mysql database, and the other to actually publish the
output to a .htm file. The following example shows us grabbing
data from the database and then using the xslt_process() function
to combine this data file a .xsl file residing on the server...
<?php
include("../../includes/connect_to_db.inc");
$query = mysql_query("select * from mytbl where mytbl_id=1");
$mydata = mysql_fetch_array($query);
$xmlString = '<?xml version="1.0"?><data>';
$xmlString .=
'<mytbl_id>'.$mydata["mytbl_id"].'</mytbl_id>';
$xmlString .=
"<mytbl_title>".$mydata["mytbl_title"]."</mytbl_title>";
$xmlString .= "<mytbl_filename>".
$mydata["mytbl_filename"]."</mytbl_filename>";
$xmlString .= "</data>";
//create instance of xslt parser
$xh = xslt_create();
//store xmlString in an array using a key '/_xml'
$arguments = array('/_xml' => $xmlString);
//to write data to a file
xslt_process($xh, 'arg:/_xml', 'style.xsl', 'result.htm', $arguments);
//to view in brower
echo(xslt_process($xh, 'arg:/_xml', 'style.xsl', NULL, $arguments));
?>
The above function works well, although you can't seem to view
the resulting htm document in the browser and write to a file at
the same time...instead you have to call the function twice, once
to write data to a file and once to display data in a browser.
-----------------------
here's a simple style.xsl file that works with this example...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
</head>
<body>
<h1>Here's my data!</h1>
<xsl:value-of select="data/mytbl_title" /><br />
<xsl:value-of select="data/mytbl_filename" /><br />
</body>
</html>
</xsl:template>
</xsl:stylesheet>
enjoy!
Sanj Maghera
--
http://www.php.net/manual/en/function.xslt-process.php
http://master.php.net/manage/user-notes.php?action=edit+26746
http://master.php.net/manage/user-notes.php?action=delete+26746
http://master.php.net/manage/user-notes.php?action=reject+26746