note 61373 added to function.xsl-xsltprocessor-register-php-functions

From: Date: Wed, 01 Feb 2006 20:17:13 +0000
Subject: note 61373 added to function.xsl-xsltprocessor-register-php-functions
Groups: php.notes 
Request: Send a blank email to php-notes+get-102838@lists.php.net to get a copy of this message
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? ---- Server IP: 216.194.113.175 Probable Submitter: 208.190.67.156 ---- Manual Page -- http://www.php.net/manual/en/function.xsl-xsltprocessor-register-php-functions.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+61373 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61373&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61373&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61373&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61373&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61373&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61373&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61373&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+61373&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#102838) next »