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

Subject: Re: [xsl] How to select for ' in XPATH?
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Wed, 5 Aug 2009 22:30:06 +0200
> 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: [xsl] 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