View Single Post
  #1 (permalink)  
Old May 23rd, 2006, 04:22 PM
Brian Campbell Brian Campbell is offline
Authorized User
 
Join Date: Oct 2004
Location: Denver, CO, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default replace ' and " with \' and \"

I'm new to XSLT...I have values in my XML that i'm trying to pass via javascript...however, to do so i need to escape double and single quotes. i found the following code, but i have no idea how to implement it.

Code:
<xsl:template name=“common_js_escape”>
        <!– required –>
        <xsl:param name=“text”/>
        <xsl:variable name=“tmp”>

                <xsl:call-template name=“replace-substring”>
                        <xsl:with-param name=“from” select=“‘&quot;’”/>
                        <xsl:with-param name=“to”>\"</xsl:with-param>
                        <xsl:with-param name=“value”>
                                <xsl:call-template name=“replace-substring”>
                                        <xsl:with-param name=“from”>&apos;</xsl:with-param>
                                        <xsl:with-param name=“to”>\’</xsl:with-param>
                                        <xsl:with-param name=“value” select=“$text” />   
                                </xsl:call-template>
                        </xsl:with-param>
                </xsl:call-template>

        </xsl:variable>
        <xsl:value-of select=“$tmp” />
</xsl:template>
and that template seems to rely on this one...

Code:
<xsl:template name=“replace-substring”>
      <xsl:param name=“value” />
      <xsl:param name=“from” />
      <xsl:param name=“to” />
      <xsl:choose>
         <xsl:when test=“contains($value,$from)”>
            <xsl:value-of select=“substring-before($value,$from)” />
            <xsl:value-of select=“$to” />
            <xsl:call-template name=“replace-substring”>
               <xsl:with-param name=“value” select=“substring-after($value,$from)” />
               <xsl:with-param name=“from” select=“$from” />
               <xsl:with-param name=“to” select=“$to” />
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select=“$value” />
         </xsl:otherwise>
      </xsl:choose>
</xsl:template>
i need to apply it to <xsl:value-of select="description" /> and <xsl:value-of select="title" /> ...can anyone dumb this down for me? :)