xsl-list
[Top] [All Lists]

Re: [xsl] How to select for ' in XPATH?

2009-08-05 14:37:14
There was a typo in my last email, '%22' works for "
"/*/*/*[contains(normalize-space(.),'%22')])"
and '%27' does not work for '
( the %22 gets converted to " character by unescape(s) )

you are left with breaking up the string into components that
contain no single quote and components that contain a single quote and
then concatenate them e.g. if the selection on the page is e.g.
What's that?
you use
"//*[contains(., concat('What', \"'\", ' that?')"

Good idea to break this up and concatenate.
But the basic problem remains, how to match for the single " ?

\"'\" does not work :-(


Implementing breaking up the string with JavaScript should be possible
although having to stuff all that into a bookmarklet might get ugly.
Perhaps this might get ugly, but not without a solution to match for
the single " character ...


Mit besten Gruessen / Best wishes,

Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Erich Baier
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


                                                                           
             Martin Honnen                                                 
             <Martin(_dot_)Honnen(_at_)gm                                       
      
             x.de>                                                      To 
                                       
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com     
             08/05/2009 08:13                                           cc 
             PM                                                            
                                                                   Subject 
                                       Re: [xsl] How to select for &apos;  
             Please respond to         in XPATH?                           
             xsl-list(_at_)lists(_dot_)mu                                       
      
              lberrytech.com                                               
                                                                           
                                                                           
                                                                           
                                                                           




Hermann Stamm-Wilbrandt wrote:

My real problem seems to be that I need a XPATH 1.0 solution since
I want to do this in a browser environment, right?


The real problem is as follows:
- open an arbitrary web page in Firefox browser

- with a bookmarklet do an arbitrary selection in that page
  (http://en.wikipedia.org/wiki/Bookmarklet)

- then the bookmarklet generates eg. the following xpath:
  "//*[contains(normalize-space(.),'xyz')]"
  where xyz is replaced by the actual selection data

- then Mozilla's document.evaluate() is used to determine the
  corresponding node in the DOM


Any hint what can be done to make this work?
(I have no control over the webpage nor control over user selection)

XPath 1.0 has no escape mechanism for string literals. Unless you can
use variables (and I don't know of a way with document.evaluate to do
that) you are left with breaking up the string into components that
contain no single quote and components that contain a single quote and
then concatenate them e.g. if the selection on the page is e.g.
What's that?
you use
"//*[contains(., concat('What', \"'\", ' that?')"
Implementing breaking up the string with JavaScript should be possible
although having to stuff all that into a bookmarklet might get ugly.


--

             Martin Honnen
             http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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>
--~--