tags:

views:

121

answers:

1

I'm using the xpath engine on Firefox. I have html:

<span>
   <b>prefix one</b> not bold part
</span>
<span>
   prefix two not bold part
</span>

I want all the spans that have child text that start with "prefix one".

I tried the xpath:

//span[starts-with(child::text(), "prefix one")]

but this doesn't work because the b tag is interfering. How do you solve this?

thanks

+1  A: 

If you know that spans is not nested into other spans you can try this:

//span[ starts-with( descendant-or-self::*/text(),"prefix one" ) ]

descendant-or-self::*/text(), should return all text nodes which are in this subtree. I don't know how starts-with() exactly works but I suppose when some of text() nodes in subtree starts with "prefix one" that condition is true

Gaim
This is equivalent to `//span[starts-with(., 'prefix one')]` or, more robust, `//span[starts-with(normalize-space(), 'prefix one')]`
Tomalak