passin XML parameters

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

passin XML parameters

Post 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
User avatar
shoebappa
Forum Contributor
Posts: 158
Joined: Mon Jul 11, 2005 9:14 pm
Location: Norfolk, VA

Post 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...
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post 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
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
Post Reply