How do I pass a variable from a URL to a XSL stylesheet?
January 8, 2004 5:19 PM
Subscribe
How do I pass a variable from a URL to a XSL stylesheet? I'm using PHP with Sablotron to parse the static XML and XSL files. [More inside]
I've been trying to find a way to get variables from the URL to the XSL style sheet so I can match a particular day in a week long weather report.
Say the url is:
http://riffola.com/weather/?location=11355&forecast&day=Friday
I can use PHP to get the right XML file using the location, but I dont know how to pass the day variable info to the XSL file.
Now I want to use that day variable from the URL to grab only Friday's weather report.
Here's a sample XML file of the weather report:
http://riffola.com/weather/cache/11355forecast.xml
As you can see <day d="2" t="Friday" dt="Jan 9"> has Friday in it, and I don't want to list any other day's details.
I want to use Sablotron to parse the XML and XSL. I can't find a way to do this. Is this even possible? Or should I just cave in and create 7 stylesheets for each day of the week?
I've had suggestions about creating a new XML from the cached file. I am not sure if that's going to be less effort than making 7 stylesheets for each day.
posted by riffola to computers & internet (4 comments total)
<xsl:param name="day">Some sensible value</xsl:param>at the top inside <xsl:stylesheet> and then from PHP pass the parameters in using a named array, as in
$xslt_params['day'] = $something;xslt_transform ($xsl_file, $xml_file, $result_file, $xslt_params);
posted by holloway at 5:29 PM on January 8, 2004