|
xslt_create
Create a new XSLT processor
(PHP 4 >= 4.0.3)
Example 2659. xslt_create() example<?php Code Examples / Notes » xslt_createkerry kobashi
It should be noted that xslt_create() will return FALSE in the case of failure (Sablotron processor could not be created). This, obtained from looking at the source code extension. garth
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. myadzel
All for a long time know about a problem xslt-transformation in php. We shall try a trivial way, knowing, that xslt_process () accepts string or resources in it's parameters. function xslt ($xml, $xsl) { $xh = @xslt_create(); $args['xml'] = join ('', file ($xml)); $args['xsl'] = join ('', file ($xsl)); // try with a string $result = @xslt_process ($xh, 'arg:/xml', 'arg:/xsl', NULL, $args); // try with resource if (!$result) { $result = @xslt_process ($xh, $xml, $xsl); } @xslt_free ($xh); return $result; } For example: echo xslt ('./index.xml', './index.xsl'); |
Change Languagexslt_backend_info xslt_backend_name xslt_backend_version xslt_create xslt_errno xslt_error xslt_free xslt_getopt xslt_process xslt_set_base xslt_set_encoding xslt_set_error_handler xslt_set_log xslt_set_object xslt_set_sax_handler xslt_set_sax_handlers xslt_set_scheme_handler xslt_set_scheme_handlers xslt_setopt |