note 97468 added to xsltprocessor.registerphpfunctions

From: Date: Wed, 21 Apr 2010 17:44:45 +0000
Subject: note 97468 added to xsltprocessor.registerphpfunctions
Groups: php.notes 
Request: Send a blank email to php-notes+get-168479@lists.php.net to get a copy of this message
The missing string-replace function in XSLT 1.0 is an all-time classic. You may either use PHP's str_replace function or (if you wish to stay language-independent) use an XSLT 1.0 implementation: <xsl:template name="str_replace"> <xsl:param name="subject"/> <xsl:param name="search"/> <xsl:param name="replace"/> <xsl:choose> <xsl:when test="contains($subject, $search)"> <xsl:value-of select="substring-before($subject, $search)"/> <xsl:copy-of select="$replace"/> <xsl:call-template name="str_replace"> <xsl:with-param name="subject" select="substring-after($subject, $search)"/> <xsl:with-param name="search" select="$search"/> <xsl:with-param name="replace" select="$replace" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$subject" /> </xsl:otherwise> </xsl:choose> </xsl:template> This template is to be called as follows: <xsl:call-template name="str_replace"> <xsl:with-param name="subject">The string being searched and replaced on, otherwise known as the haystack.</xsl:with-param> <xsl:with-param name="search">The value being searched for, otherwise known as the needle.</xsl:with-param> <xsl:with-param name="replace">The replacement value that replaces found search values.</xsl:with-param> </xsl:call-template> ---- Server IP: 212.124.37.9 Probable Submitter: 80.69.35.102 ---- Manual Page -- http://www.php.net/manual/en/xsltprocessor.registerphpfunctions.php Edit -- https://master.php.net/note/edit/97468 Del: integrated -- https://master.php.net/note/delete/97468/integrated Del: useless -- https://master.php.net/note/delete/97468/useless Del: bad code -- https://master.php.net/note/delete/97468/bad+code Del: spam -- https://master.php.net/note/delete/97468/spam Del: non-english -- https://master.php.net/note/delete/97468/non-english Del: in docs -- https://master.php.net/note/delete/97468/in+docs Del: other reasons-- https://master.php.net/note/delete/97468 Reject -- https://master.php.net/note/reject/97468 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168479) next »