[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] multiple search and replace
The following snip works fine but can anyone tell me whether there is a better more efficient way to replace more than one item. <xsl:template match="text()"> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="." /> <xsl:with-param name="find" select="'?degrees?'" /> <xsl:with-param name="replace" select="'°'" /> <xsl:with-param name="find2" select="'Nm'" /> <xsl:with-param name="replace2" select="'N·m'" /> </xsl:call-template> </xsl:template> <!-- template to look for all instances of string $find and replace that with string $replace --> <xsl:template name="_replace_string"> <xsl:param name="string" select="''"/> <xsl:param name="find" select="'find'"/> <xsl:param name="replace" select="'replace'"/> <xsl:param name="find2" select="'find2'"/> <xsl:param name="replace2" select="'replace2'"/> <xsl:choose> <xsl:when test="contains($string,$find)"> <xsl:value-of select="concat(substring-before($string,$find),$replace)"/> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="substring-after($string,$find)"/> <xsl:with-param name="find" select="$find"/> <xsl:with-param name="replace" select="$replace"/> </xsl:call-template> </xsl:when> <xsl:when test="contains($string,$find2)"> <xsl:value-of select="concat(substring-before($string,$find2),$replace2)"/> <xsl:call-template name="_replace_string"> <xsl:with-param name="string" select="substring-after($string,$find2)"/> <xsl:with-param name="find2" select="$find2"/> <xsl:with-param name="replace2" select="$replace2"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> </xsl:template> Confidentiality Notice The information contained in this e-mail is confidential and intended for use only by the person(s) or organization listed in the address. If you have received this communication in error, please contact the sender at O'Neil & Associates, Inc., immediately. Any copying, dissemination, or distribution of this communication, other than by the intended recipient, is strictly prohibited.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|