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

Re: How to select for ' in XPATH?

Subject: Re: How to select for ' in XPATH?
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Wed, 05 Aug 2009 20:13:15 +0200
Re:  How to select for &apos; in XPATH?
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/

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.