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

RE: Xoath quote escaping

Subject: RE: Xoath quote escaping
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 28 Apr 2007 18:02:53 +0100
RE:  Xoath quote escaping
In XPath 1.0, without variables, you're basically stuck with the XPath
expression

concat("This is some ", '"', "quoted", '"', " content of Ted's")

and then of course you have to backslash-escape the quotes to get them
through Javascript.

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Duane Hitz [mailto:dhitz@xxxxxxxxxxxxxxxx] 
> Sent: 28 April 2007 15:27
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Xoath quote escaping
> 
> All,
> 
> I have a situation where I am building an XPath expression in 
> JavaScript to select nodes from an XML document.  The content 
> of the nodes could contain double quotes, single quotes or 
> both at the same time.  It is user-entered data, so I have no 
> control ultimately over what the content contains.
> 
> The content might be (brackets excluded): [This is some 
> "quoted" content of Ted's]
> 
> The dynamically built xpath expression might look like (where 
> subNodeValue is the above content):
> 
> 1) "//node["  + subNodeName + " = '" + subNodeValue + "']"
> 
> ... except for the single quote problem... or:
> 
> 2) "//node["  + subNodeName + " = \"" + subNodeValue + "\"]"
> 
> ... except for the double quote problem... or even:
> 
> 3) "//node["  + subNodeName + " = &quot;" + subNodeValue + "&quot;]"
> 
> ...except that this just doesn't work.
> 
> Any thoughts on how to make this work?  Is it possible?
> 
> I've read everything I can find on quote escaping (on this list and
> elsewhere) and there doesn't appear to be a solution that 
> covers this case (I know XPath 2 is supposed to allow "" 
> escaping - unfortunately, we're stuck on IE6+ & MSXML3).
> 
> We are dynamically displaying rows in a table that meet the 
> xpath criteria... setting a @showing attribute and then 
> re-transforming... so it really has to be in JavaScript.
> 
> One option would be to replace (s/"/'/g or s/"/''/g) all 
> double quotes on the server side when building the XML - and 
> then use option 2 above.  I don't really want to change 
> user-entered data. It is, sadly, what I've come down to.  I'm 
> hoping there's a more elegant solution to this.
> 
> Thanks for any help...
> 
> Duane 

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.