Page 1 of 1

passin XML parameters

Posted: Mon Oct 31, 2005 7:09 pm
by kendall
Can i pass parameters to xml/xsl pages?

im thinking if i cant i may need to use javascript.
im trying to build a low budget product catalogue which the client can update buy editing an xml file.

has anyone ever used xml/ xsl for such a task?

what about dynamically loading xsl stylesheets based on parameters passed tru urls?

Kendall

Posted: Tue Nov 01, 2005 7:28 am
by shoebappa
I have in the non-php5 functions, but I assume you can do similar with the new way.

The last argument would be an array of parameters used in your xsl stylesheet, with the names as the keys.

mixed xslt_process ( resource xh, string xmlcontainer, string xslcontainer [, string resultcontainer [, array arguments [, array parameters]]] )

So something like:

Code: Select all

$arguments = array(
     '/_xml' => $xml,
     '/_xsl' => $xsl
);

$parameters = array("param1" => 100, "param2" => 10);

// Allocate a new XSLT processor
$xh = xslt_create();

// Process the document
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments, $parameters);
Then your xsl would have:

Code: Select all

<param name="param1"></param>
<param name="param2"></param>
Before any of your template match stuff, and you can use the params like constants...

Posted: Tue Nov 01, 2005 7:41 am
by kendall
have in the non-php5 functions, but I assume you can do similar with the new way.
:?: :?:
i dont have php 5 so i thought javascript would probably been easier?

what is it exactly did you do? as i cannot comprehend what you are saying

Posted: Tue Nov 01, 2005 8:56 am
by timvw
In PHP4, you'll probably be using sablotron extension: http://be2.php.net/xslt.

=> xslt_process has a parameter that accepts parameters. (as already shown)

In PHP5, you'll be using the libxslt exteions: http://be2.php.net/xsl.

=> Use the setParameter method.