note 13366 deleted from ref.xslt by sobak

From: Date: Tue, 22 Nov 2016 03:30:53 +0000
Subject: note 13366 deleted from ref.xslt by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207330@lists.php.net to get a copy of this message
Note Submitter: d dot u at mail dot com ---- I extended the example of shanks (very helpful for me tnx), so you can call php inside your xslt file, I had the problem to pass url-parameters and did not understand how to solve it, so I use php. <code> <?php /** * * A class to transform XML through XSLT using PHP4 Sablotron extension * */ ####################################################################### ## file extended by Daniel Unterberger (d.u@mail.com) ## changes: some php:eval's added class xsltTransform { var $xsl_file; var $xml_file; var $fileName; /** * Constructor to the xsl_transform ticket * * @param $xsl_file The XSLT file containing the transformation info * @param $xml_file The XML file containing the actual data * @see readFile() */ function xsltTransform($xsl_file = '', $xml_file = '') { $this->xsl_string = $this->readFile($xsl_file,'php:eval'); $this->xml_string = $this->readFile($xml_file); } /** * Function to read through the file * * @param $fileName Which file to read? * */ function readFile($fileName,$php_eval="") { // get contents of a file into a string $fd = fopen( $fileName, "r" ); $content = fread( $fd, filesize( $fileName ) ); fclose( $fd ); ################################################## ## extension by Daniel Unterberger (d.u@mail.com) while ( $php_eval and ( $pos_start=strpos($content,'<php:eval>') )) { $pos_end=strpos($content,'</php:eval>'); $content=substr($content,0,$pos_start). eval( substr($content,$pos_start+10,$pos_end-$pos_start-10) ). substr($content,$pos_end+11); } if ($GLOBALS["debug"]=="ON") print "<xmp>$content</xmp>"; ## see xslt-file for debuggin if you call page.php?debug=ON (remove on life-server) ################################################### ## end extension return $content; } /** * Function to apply the actual transformation * */ function applyTransformation() { $this->result = ''; $this->msg = xslt_process($this->xsl_string, $this->xml_string, $this->result); if(!$this->msg) print ("Transformation failed."); return $this->result; } // End of class, do not remove } ?> </code> in the xslt you can call it now with ... <tag><php:eval> return $GLOBALS["filter"]; /* all php allowed */ </php:eval></tag> ... ------------------------------- hope this gives new inspiration (d.u)

« previous php.notes (#207330) next »