note 26746 deleted from function.xslt-process by sobak

From: Date: Tue, 22 Nov 2016 03:32:56 +0000
Subject: note 26746 deleted from function.xslt-process by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207351@lists.php.net to get a copy of this message
Note Submitter: sanj at wiredesign dot com ---- 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

« previous php.notes (#207351) next »