[Greasemonkey] XPath n00b help

Mitchell Mebane mitchell.mebane at gmail.com
Sun Feb 12 13:07:53 EST 2006


Roderick McGuire wrote:
> Roderick McGuire wrote:
>
>> First off, I believe text selects a text node. It isn't a function 
>> that returns the text of a node. so for the first part you want:
>>
>>  //strong/text()[., contains('Item:')]
>>
>> I would make the search a little more constrained by as:
>>
>>  //span [@class='galheader']/strong/text()[., contains('Item:')]
>>
>> But I don't understand why you are doing that. Actually what you want 
>> is the text node under a galheader preceded by a strong image count.
>>
>> I would write that as:
>>
>>  //span 
>> [@class='galheader']/text()[preceding-sibling::strong//text()[., 
>> contains('Image')]]
>>
>> I've had proroblems with the various axis declarations in XPATH and 
>> I'm not sure which of them are actually implemented in Firefox.
>
> Woops, the XPATHS should really be:
>
>  //strong/text()[contains(., 'Item:')]
>
> //span [@class='galheader']/strong/text()[contains(., 'Item:')]
>
> //span 
> [@class='galheader']/text()[preceding-sibling::strong//text()[contains(., 
> 'Image')]]
>
>
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>
Thanks for the link to XPather, it is extremely useful.

I got the [text()=] example from here:
http://ripwiki.pbwiki.com/XPathTips

It seems to work just fine used like so:
//strong[text()="Item:"]//following-sibling::text()[1]

*shrug*

--Mitchell Mebane


More information about the Greasemonkey mailing list