[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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 + " = "" + subNodeValue + ""]" > > ...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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|