Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 10th, 2006, 08:47 PM
Authorized User
 
Join Date: Feb 2005
Location: Smithtown, NY, USA.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to IronStar
Default How do you translate an apostrophe?

Hi all,

I have data that has embedded apostrophes and I need to replace them with blanks. I use the following code:

<xsl:value-of select="translate($desc, '#x27;', ' ')"/>

or

<xsl:value-of select="translate($desc, '&apos;', ' ')"/>

or

<xsl:value-of select="translate($desc, '&quot;', ' ')"/>

and the result is the same:

javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: misquoted literal... expected single quote!

Has anyone run into this before? How do I translate a single quote/apostrophe?

Thanks,
Tom
Reply With Quote
  #2 (permalink)  
Old November 11th, 2006, 05:00 AM
mhkay's Avatar
Wrox Author
Points: 18,274, Level: 58
Points: 18,274, Level: 58 Points: 18,274, Level: 58 Points: 18,274, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,932
Thanks: 0
Thanked 282 Times in 277 Posts
Default

In 2.0:

<xsl:value-of select="translate($desc, '''', ' ')"/>

In 1.0:

<xsl:value-of select='translate($desc, "&apos;", " ")'/>

or

<xsl:variable name="apos">'</xsl:variable>
<xsl:value-of select="translate($desc, $apos, ' ')"/>

Always remember that XML entity and character references are expanded before the XPath parser kicks in, so they can't be used to escape something that's significant to XPath.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old November 13th, 2006, 12:35 PM
Authorized User
 
Join Date: Feb 2005
Location: Smithtown, NY, USA.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to IronStar
Default

Thanks for the input. That solved the problem.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
apostrophe ' problem in comparison ramniwas Visual Basic 2005 Basics 4 April 4th, 2008 12:21 AM
cdonts and apostrophe bostonrose Classic ASP Components 3 October 23rd, 2006 09:20 AM
Apostrophe in a textarea myself Classic ASP Professional 9 June 8th, 2006 08:32 AM
Javascript validation for apostrophe crmpicco Javascript How-To 2 March 2nd, 2005 06:57 AM
Apostrophe in textarea Renu ASP.NET 1.0 and 1.1 Basics 3 September 8th, 2004 03:13 PM



All times are GMT -4. The time now is 04:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.