[thelist] String Manipulation

Jason Bauer jbauer at mtu.edu
Thu Jun 27 15:18:01 CDT 2002


At 06:49 PM 6/22/02 -0500, you wrote:
><category>
>   <category_name>About Us</category_name>
></category>
>
>I need to use this category_name in my html, but not like that. More
>specifically, I need to take either take out that space and have
>AboutUs, or just use the first word, About. It also needs to be set
>up so that if category_name is just one word, it will be preserved.

I do something like this to keep my links with spaces from breaking in
Netscape:

         <xsl:template name="fix_spaces">
                 <xsl:param name="value" />

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

This template recursively goes through the value sent to the template and
replaces ' ' with '%20'. You can slightly modify it to simply remove the
spaces, or get rid of the recursion (remove the <xsl:call-template>) to
just get the first word of a string. Enjoy!


--
Jason Bauer
jbauer at mtu.edu
Michigan Tech Fund
Web Site Coordinator
http://www.mtf.mtu.edu/




More information about the thelist mailing list