note 23013 added to function.xslt-process

From: Date: Sat, 06 Jul 2002 18:12:28 +0000
Subject: note 23013 added to function.xslt-process
Groups: php.notes 
Request: Send a blank email to php-notes+get-32687@lists.php.net to get a copy of this message
This in example on using variables from php in xsl-stylesheets (Sablotron 0.95) with: <xsl:param name="foo" /> and how to pass the param from php to Sablotron (I'm using Sablotron 0.95) The php-wrapper to Sablotron has changed somewhat in 4.0.6, so I'm using the new (experimental) syntax. Maybe this could change again in the future I use 4.2.1 which is compiled with: './configure' '--with-mysql' '--with-apxs' '--enable-xslt' '--with-xslt-sablot=/usr/local/lib' '--with-expat-dir=/usr' '--with-dom' '--with-zlib-dir=/usr' When you want to use a param passed to the xslt_process you have to put it in the top level of the xslt-script, otherwice it won't work (means: before defining any template) Afterwards you can use the passed param with <xsl:value-of select="$yourparamname" /> in the template. example: ====> xsl-stylesheet <==== <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="1.0" encoding="UTF-8" indent="no" omit-xml-declaration="yes" doctype-public="-//W3C/DTD XHTML 1.0 Transitional//EN" doctype-system=" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" standalone="yes" media-type="text/html" /> <xsl:param name="tpsession" /> <xsl:template match="/root/output"> this is the template stuff. and this is the param <xsl:value-of select="$tpsession" /> </xsl:template> </xsl:stylesheet> ====> end of xsl - stylesheet <==== o.k. -> to call the xslt_parser (Sablotron 0.95 in my case) with params do this: <?php /* php script */ $xh = xslt_create(); $arg = array( '/_xml' =>$t_xmlString, '/_xsl' => $t_xslString ); $param = array('tpsession' = session_name()."=".session_id()); $result = @xslt_process($xh, 'arg:/_xml', 'arg:/_xsl',NULL,$arg,$param); if(!$result){ print xslt_error($xh); } else print $result; xslt_free($xh); /* end of php-script */ ?> That's it -> have fun -- http://www.php.net/manual/en/function.xslt-process.php http://master.php.net/manage/user-notes.php?action=edit+23013 http://master.php.net/manage/user-notes.php?action=delete+23013 http://master.php.net/manage/user-notes.php?action=reject+23013

« previous php.notes (#32687) next »