Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
Old November 11th, 2006, 05:00 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
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.




Similar Threads
Thread Thread Starter Forum Replies Last Post
apostrophe ' problem in comparison ramniwas Visual Basic 2005 Basics 4 April 3rd, 2008 11:21 PM
cdonts and apostrophe bostonrose Classic ASP Components 3 October 23rd, 2006 08:20 AM
Apostrophe in a textarea myself Classic ASP Professional 9 June 8th, 2006 07: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 02:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.