note 35891 deleted from function.xslt-create by sobak
| From: | sobak@php.net | Date: | Tue, 22 Nov 2016 03:33:46 +0000 |
| Subject: | note 35891 deleted from function.xslt-create by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207361@lists.php.net to get a copy of this message | ||
Note Submitter: garth at webconexion dot net
----
In order to pass PHP variables into an XSL document you need to do the following:
Firstly I created the following function to use:
function GetXHTML($sXML, $sXSL, $aParameters)
{
$hXML = xslt_create();
$aArguments = array('/_xml' => $sXML, '/_xsl' => $sXSL);
$sXHTML = xslt_process($hXML, 'arg:/_xml', 'arg:/_xsl', NULL, $aArguments,
$aParameters);
xslt_free($hXML);
return $sXHTML;
}
Then call it like thus, passing the XML and XSL as a string with the final parameter being an array
which can contain as many values as you wish to pass in:
$sXHTML = GetXHTML($sXML, $sXSL, array("age"=>"26"));
Then in the XSL document you need the following:
<xsl:param name="age" />
Then where you want to display the value of age you do this:
<xsl:value-of select="$age" />
Thanks now.