xsl-list
[Top] [All Lists]

RE: [xsl] Xoath quote escaping

2007-04-28 10:03:27
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(_at_)servicelogix(_dot_)com] 
Sent: 28 April 2007 15:27
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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 



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>