Voting

: min(eight, eight)?
(Example: nine)

The Note You're Voting On

hopeseekr at gmail dot com
19 years ago
One of the peskiest things I had problems with was encoding URL parameters. I mean, pretend you want to populate a link with "search+terms" instead of just "search terms". I was including two seperate URLs in the XML and that was ludicrous.

Below is a far more elegant PHP+XSLT solution. You will also see it uses two *undocumented* features of registerPHPFunctions(), namely php:functionString() and the passing of parameters to the function. I figured this out by trial and error; I really hope this note helps you as it *greatly* expands the power of php functions in XSLT!

<?php
/* --- XML input --- */
<search_results>
<
query>concert tickets</query>
</
search_results>

/* --- XSL code --- */
<!-- Display query -->
<
xsl:template match="search_results">
<!--
Get URL-encoded string via PHP -->
<
xsl:variable name="safeurl" as="xs:string" select="php:functionString('urlencode', query)" />
<
p>Your search for <em><xsl:value-of select="query"/></em> can be continued at <a href="http://www.tixtix.com/search.php?q={$safeurl}">our search engine</a></p>
</
xsl:template>

/* --- XHTML output --- */
<p>Your search for <em>concert tickets</em> can be continued at <a href="http://www.tixtix.com/search.php?q=space+cowboy">our search engine</a></p>
?>

Cool, huh?

<< Back to user notes page

To Top