Re: [xsl] Spaces to %20

Subject: Re: [xsl] Spaces to %20
From: pcarey@xxxxxxxxxxx
Date: Fri, 6 Jul 2007 08:37:24 -0400
In XSLT 1, something like this:

<xsl:template name="replace">
 <xsl:param name="string"/>
 <xsl:choose>
   <xsl:when test="contains($string, ' ')">
      <xsl:value-of select="substring-before($string,' ')"/>
      <xsl:text>%20</xsl:text>
      <xsl:call-template name="replace">
        <xsl:with-param name="string" select="substring-after($string,'
')"/>
      </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
      <xsl:value-of select="$string"/>
   </xsl:otherwise>
 </xsl:choose>
</xsl:template>

In your case, you'd pass $kw to this template.

Hope this helps,

--PETE



                                                                           
             Kerry Kobashi                                                 
             <kkobashi@comcast                                             
             .net>                                                      To 
                                       xsl-list@xxxxxxxxxxxxxxxxxxxxxx     
             07/06/2007 02:40                                           cc 
             AM                                                            
                                                                   Subject 
                                       [xsl] Spaces to %20                 
             Please respond to                                             
             xsl-list@xxxxxxxx                                             
              lberrytech.com                                               
                                                                           
                                                                           
                                                                           



Hi all,

I need a way to convert all spaces into %20 for the anchor tag href below:

<xsl:for-each select="/article/keywords/keyword">
   <xsl:variable name="kw" select="."/>
     <a href="/search.php?keyword={$kw}" title="{$kw}">
        <xsl:value-of select="$kw" />
     </a>
   <xsl:if test="position()!=last()">, </xsl:if>
</xsl:for-each>


<?xml version="1.0" encoding="UTF-8"?>
<article>
    <keywords>
       <keyword>Cascading Style Sheet</keyword>
       <keyword>Hypertext Markup Language</keyword>
    </keywords>
</article>

Current Thread