Passing Parameters to an XSLT Stylesheet

If you need to pass data from the PHP script to the XSLT stylesheet, PHP’s xslt_process() function can be used to pass an associative arrays of parameters to the XSLT stylesheet.

You’ll remember that the xslt_process() function can accept an array containing parameter-value pairs as an optional sixth argument. These parameters can be passed on to the stylesheet and used within template rules.

Consider Listing 4.8, which creates an associative array named $params, and stores two elements containing the page title and current date in it. This associative array is then passed on to the stylesheet via the xslt_process() function.

Listing 4.8. Passing Parameters to an XSLT Stylesheet
 <?php // set the filenames ...

Get XML and PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.