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

Re: Problem using translate to escape quotes

Subject: Re: Problem using translate to escape quotes
From: Jeff Kenton <jkenton@xxxxxxxxxxxxx>
Date: Wed, 04 Dec 2002 11:13:06 -0500
xsl escape string
Kevin Collins wrote:
I have a string containing single quotes held in a variable. I want to
escape each quote by inserting a backslash before it, but I can't get it
to work. The translate function appears to be inserting the backslashes
without the quotes.

Kevin,


The translate function does single character replacement. To get what you want, you need to use some of the other string functions. Lokk at starts-with(), concat(), contains, substring-before(), etc. Since you have multiple occurences of the quote character, you will probably need to build a recursive template to get them all.

jeff




Here's a test version of the stylesheet: -------------------------------------------- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/>

<xsl:variable name="mystr">this is Kevin's 'string'</xsl:variable>

<xsl:variable name="backSlashQuote">&#92;&#39;</xsl:variable>
<xsl:variable name="backSlash">&#92;</xsl:variable>
<xsl:variable name="singleQuote">&#39;</xsl:variable>
<xsl:variable name="backSlashQuote2"><xsl:value-of select="concat(
$backSlash, $singleQuote )"/></xsl:variable>

<xsl:variable name="mystr_escaped">
 <xsl:value-of select="translate( $mystr, $singleQuote, $backSlashQuote
)"/>
</xsl:variable>

<xsl:template match="/">
<html>
 <body>
  <xsl:value-of select="$mystr"/>
  <br/>
  <xsl:value-of select="$mystr_escaped"/>
 </body>
</html>
</xsl:template>

</xsl:stylesheet>
--------------------------------------------




-- -------------------------- Jeff Kenton DataPower Technology, Inc.



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-2013 All Rights Reserved.