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

Trouble understanding how to use replace()

Subject: Trouble understanding how to use replace()
From: cknell@xxxxxxxxxx
Date: Fri, 06 Jan 2006 10:55:20 -0500
perl replace
Once upon a time I was adept with perl and handy with regular expressions. It has been some years since I worked with perl and my regex skills have rusted.

I have a document I'm transforming to CSV in order to import its contents to a database. The file contains text including double and single quotes and commas. The instructions for preparing the CSV file direct me to enclose any strings containing commas in quotation marks. Some of my text includes lists of items enclosed in quotation marks and separated by commas. I have no problem with using the <xsl:text> element to surround the whole string in double-quotes, but that leaves some troublesome double-quotes in the original string that cause the export field to break up.

So I thought the best approach would be to use the new XPath 2.0 "replace()" function to replace all the double-quotes in the original string with single-quotes. This is the construct I tried that's giving me a problem,

<xsl:value-of select="replace(req-text,"\"","'")" />

Among that nest of short strokes is double-quote, backslash, double-quote, double-quote, and just after the second comma I've got double-quote, single-quote, double-quote.

As I understand the function, it takes three arguments: input, a regular expression, and the text to replace the matched expression. 

The first argument I gave it is the name of an element from the current context. If I simply use select="req-text" I get the text of the element, so there is no issue with this not containing a string.

The second argument is a double-quote, which is what I want to replace, and the third agrument is a single-quote, the character I want to substitute for the double-quote. In perl I would use the backslash to escape the double-quote inside the double-quotes of the second argument. Apparently this is not legal in XPath 2.0.

I've been perusing Michael Kay's "XPath 2.0", but I can't find what must be in there, an explanation of how to do this.

Any insight will be gratefully received.

-- 
Charles Knell
cknell@xxxxxxxxxx - email

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.