[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: translate (string, ''' , '''' )

Subject: Re: translate (string, ''' , '''' )
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Mon, 5 Mar 2001 18:18:09 +0000
039
Hi Pascal,

> I Have a XSL as :
>
> <xsl:variable name="N" >
> <xsl:value-of select="translate(/Legende, ''', '''' ) " />
> </xsl:variable>
>
> I want to translate my " isn't " as " isn''t"

The translate() function only works for translating single characters
into other single characters - you can't use it to replace a single
character with more than one character as you're doing here.

Instead, you have to use a recursive named template.  If it finds an
apostrophe in the string, it gives (a) the string before the
apostrophe (b) two apostrophes and (c) whatever you get if you call
the template on the string after the apostrophe.  If it doesn't find
an apostrophe in the string, it just gives you the string:

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

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.