Jump to content

Two params for templates


kvnmck18

Recommended Posts

I'm trying to make an image gallery with options...There are thumbails on the side that open up a picture.But I want to have options for the thumbnails: default (all pictures), just "Wedding", just "Karaoke", and just "Other".This involves two params and two templates and I can't get it to work.XSL:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output omit-xml-declaration="yes" /><xsl:param name="photo" select="'123456'"/><xsl:param name="page" select="'Weddings'"/><xsl:template match="/"><div id="content_right"><div id="content_right_title"><div id="titles">Images</div></div><div id="text"><center><xsl:for-each select="//image[@cat=$page]"><a href="?photo={@id}"><img src="{@thumb}" id="imgthumbs"/></a></xsl:for-each></center></div></div><xsl:apply-templates select="//image[@id=$photo]"/></xsl:template><xsl:template match="//image"><div id="content_left"><div id="content_left_title_green"><div id="titles" class="top_title"> <xsl:value-of select="@cat"/> </div></div><div id="text"> <center><img src="{@src}" alt="{@title}" id="imgshow"/></center></div></div></xsl:template></xsl:stylesheet>

PHP:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>RadioActive Productions</title><link rel="stylesheet" type="text/css" href="stylz.css" /><script src="ra.js" type="text/javascript"></script></head><body><div id="header_holder"><div id="header"><script type="text/javascript">Menu();</script></div></div><div id="holder"><div id="content_holder"><?php$xmlfile = "xml.xml";$xslfile = "xsl.xsl";if ($_GET['page']) {$expression= array("page" => $_GET['page']);} if ($_GET['photo']) {$expression= array("photo" => $_GET['photo']);} else {$expression=NULL;}$args = $expression;$engine = xslt_create();$output = xslt_process($engine, $xmlfile, $xslfile, NULL, NULL, $args);print $output;xslt_free($engine);?></div><div id="border_bottom"><img src="images/cord_border_right_corner.gif" id="border_bottom_corner"/><img src="images/left_cord_rip.gif" class="border_bottom_left" /></div></div></body></html>

XML sample:

<images><image cat="Weddings/Karaoke/Other" src="image.jpg" thumb="image_thumb.jpg" id="123456" /></images>

The thumbnails work when clicked it opens the right picture I just can't get the "?page=" to work, it's just "stuck" on the Weddings thumbnails.

Link to comment
Share on other sites

I understand the idea, but I'm unable to visualize the problem. Do you have some sort of testing page to which you could link to?

Link to comment
Share on other sites

Hm. After your PM with the link, I think I'm able to see the problem. I think the best solution is to generate the whole:

<a href="?page={@cat}&photo={@id}"><img src="{@thumb}" id="imgthumbs"/></a>

with condtions in the attribute. To put it in code, something like this:

<a><xsl:attribute name="href"><xsl:if test="$category != 'Weddings'">?page=<xsl:value-of select="@cat"/>&amp;</xsl:if>photo={@id}</xsl:attribute><img src="{@thumb}" id="imgthumbs"/></a>

Link to comment
Share on other sites

I said that in the PM but I had a small typo...and that doesn't work. At least when I tried it out with "...php?page=Foam%20Parties&photo=radio452171fd2afcf"...it brings up the thumbs of just the Foam Parties but not the picture with that id, goes to the default value picture.

Link to comment
Share on other sites

I'm not sure, but I think the PHP might be the cause for this one. I mean... setting up the two parameters should have worked. Try making:

if ($_GET['page']) {$expression= array("page" => $_GET['page']);}

into

if ($_GET['page']) {$expression= array("page" => $_GET['page']);}else {$expression=NULL;}

or perhaps remove the

else {$expression=NULL;}

from

if ($_GET['photo']) {$expression= array("photo" => $_GET['photo']);} else {$expression=NULL;}

After all, "NULL" resets the whole array as far as I'm aware.You seriosly need to think about moving on to PHP5 and libxslt. With it, setting a parameter is as easy as:

$xslt->setParameter(NULL, 'ParameterName', 'ParameterValue');

and repeating this twice sets two parameters and so on. Not to mention that libxslt has 99% XSLT 1.0 support and a variety of EXSLT extensions too.

Link to comment
Share on other sites

Yeah, that doesn't work. I wish I could go to php5 but all I've ever done has been 4...I don't want to change everythign...and move away from what I am used to using. :\ Any other ideas?

Link to comment
Share on other sites

Specifying both parameters in the href works. I tryed this with my own XSLT processor:

<xsl:for-each select="//image[@cat=$page]"><a href="?photo={@id}&page={@cat}">	<img src="{@thumb}" id="imgthumbs"/></a></xsl:for-each>

of course it has bad error handling when one of the parameters is not present, but I guess your users won't care for that much.If that doesn't work for you, then the problem is with the PHP for sure.I'm not that experienced with PHP, but I think this is how you declare two members of an array:

$expression = array("photo" => $_GET['photo'], "page" => $_GET['page']);

infact, you don't need the $expression variable and the line:

$args = $expression;

You can just use

$args = array("photo" => $_GET['photo'], "page" => $_GET['page']);

By the way... do you know the greatest benefit that XSLT brings? It's portability. It can work the same in all languages that have an XSLT processor. So, you should increase the role of XSLT so that the only thing left for PHP would be initiating the XSLT processor with the proper parameters. Rewritting that sort of code from PHP4 to PHP5 (or any other server side scripting language on that matter) would be a breeze.

Link to comment
Share on other sites

$args = array("photo" => $_GET['photo'], "page" => $_GET['page']);

That is how you do an array in PHP for passing params...and I know how to do that only when there is one $_Get and the other is a default value that is to be passed such as the Date or just a saying, ect. So I guess this real problem is actually the line before all of this I don't know how to get the Get value with two different names to pass through both. Maybe this is a question for the PHP forum not XSLT....because I believe that all the XSLT is correct. boen_robot it's not that you have been stumped I just know that PHP isn't your expertise really, at least when dealing with PHP 4.You always seem to come up with an answer though so if you can think of anything please help out.You know I appreciate all your help...and thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...