Reputation: 1035
I have the following, and trying to see if there's a better approach. I know it cn be done using starts-with/contains. I'm testing with firefox 10, which I believe implements xpath 2.+.
Test node is
<a id="foo">
.
.
.
<a id="foo1">
.
<a id="foo2">
Is there a way to use wildcards to be able to get the foo1/foo2 nodes..
Something like
//a[@id =* 'foo']
or
//a[contains(@id*,'foo')]
Which would say, give me the "a" where the id starts with "foo" but has additional chars... This would then skip the 1st node with the "foo"
I thought I had seen an rticle on this, but can't find it!
As I recall, the article stated that xpath had a set of operators that could be used to designate the start/end of a given pattern in a string.
thanks
Upvotes: 9
Views: 37167
Reputation: 243449
Use:
//a[@id[starts-with(., 'foo') and string-length() > 3]]
Upvotes: 11
Reputation: 60190
Not a wildcard, but probably what you need nonetheless:
//a[(@id!='foo') and starts-with(@id,'foo')]
See W3C XPath spec.
Upvotes: 6