[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: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Thu, 6 Aug 2009 13:09:26 +0200
Re:  How to select for &apos; in XPATH?
Thank you all for the different hints!

It turned out that the following xpath expression just works with the
xpath bookmarklet from below email on the link given there:
/*/*/*[contains(.,"What's that")]

It just returns:.,
Found 1 match for xpath(/*/*/*[contains(.,"What's that")]):


And if searching for the seqence ')" which is &apos;)&quot;  this
really works fine with the alternating concat technique proposed by
Martin (but without any escaping)!

Applying this xpath
/html/body/*[contains(normalize-space(.),concat("')",'"'))]

with below xpath bookmarklet on this link
http://www.w3.org/TR/xslt

returns:
Found 2 matches for xpath(/html/body/*[contains(normalize-space(.),concat
("')",'"'))]):


/HTML/BODY/PRE[6]
...
<xsl:template match="id('foo')">
...


/HTML/BODY/PRE[66]
...
  <xsl:for-each select="document('bib.xml')">
...

So now there is a working solution.


The only question remaining is:
Is there an xpath expression for matching a string containing N &apos;
and N &quot; characters alternating without the need to have a concat
of 2*N parameters?


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


                                                                           
             Hermann                                                       
             Stamm-Wilbrandt/G                                             
             ermany/IBM@IBMDE                                           To 
                                       xsl-list@xxxxxxxxxxxxxxxxxxxxxx     
             08/05/2009 10:30                                           cc 
             PM                                                            
                                                                   Subject 
                                       Re:  How to select for &apos;  
             Please respond to         in XPATH?                           
             xsl-list@xxxxxxxx                                             
              lberrytech.com                                               
                                                                           
                                                                           
                                                                           
                                                                           




> Should be using the apostrophe attribute delimiter and double
> quote string delimiter:
>
>    '//*[contains(., "What&#x27; that?")]'

Here the 's' is missing, should be
     '//*[contains(., "What&#x27;s that")]'


I removed the question mark in order to apply that xpath to the
following old post in xsl-list archive (containing "What's that ..."):
http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200303/msg01125.html>



Below you find a "xpath" bookmarklet which allows you and others to
easily play around with xpath searches on any webpage with Firefox.
1) go to some webpage
2) click on the "xpath" bookmark    (install instructions below)
3) enter any xpath into the dialog
4) click "OK"
5) all DOM nodes matched by the xpath get marked by blue rectangles
6) displays "Found n matches for xpath(xyz)" in browser status bar


And these are the results on above mentioned link:
//table
  Found 4 matches for xpath(//table)
//h2
  Found 1 match for xpath(//h2)
/*/*/*[contains(.,"What")]
  Found 1 match for xpath(/*/*/*[contains(.,"What")])
/*/*/*[contains(.,"What&x27;")]
  Found 0 matches for xpath(/*/*/*[contains(.,"What&x27;")])

Happy xpath matching!
And hopefully someone finds the correct apostroph match that way ...


The bookmarklet works for Firefox web browsers.
1) create a bookmark named "xpath"
2) open the properties of that bookmark
3) copy and paste the complete bookmarklet below into "Location"
4) click OK.

In case the email gateway adds "interesting" characters to this post,
the complete bookmarklet can be downloaded under this link, too:
http://www.stamm-wilbrandt.de/en/xsl-list/xpath.bookmarklet.txt:


javascript:(function(){
  location.reload();

  var count=0, text, e;
  xpath=prompt("xpath()", "");
  if(xpath==null || xpath.length==0)
    return;

  var nodesSnapshot = document.evaluate(xpath, document.body, null,
                        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );

  for ( var i=0 ; i < nodesSnapshot.snapshotLength; i++ )
  {
    e = nodesSnapshot.snapshotItem(i);
    e.style.borderStyle="solid";
    e.style.borderWidth="2px";
    e.style.borderColor="blue";;

    ++count;
  }

  window.status="Found "+count+" match"+(count==1?"":"es")
               +" for xpath("+xpath+")";
})();


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



             "G. Ken Holman"
             <gkholman@CraneSo
             ftwrights.com>                                             To
                                       xsl-list@xxxxxxxxxxxxxxxxxxxxxx
             08/05/2009 09:23                                           cc
             PM
                                                                   Subject
                                       Re:  How to select for &apos;
             Please respond to         in XPATH?
             xsl-list@xxxxxxxx
              lberrytech.com








I rushed my answer and made a mistake.

At 2009-08-05 12:16 -0700, I wrote:
>In XSLT 1:
>
>   "//*[contains(., 'What&#x27; that?)]"

Should be using the apostrophe attribute delimiter and double quote
string delimiter:

    '//*[contains(., "What&#x27; that?")]'

Sorry for misleading you.

. . . . . . . . . ken


--
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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.