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
xml file to learn XPath wildcards and its style sheet which uses Xpath expressions to select a value from the elements. The most widely used type is the asterisk(*). To match all nodes below expression is used and the (//) operator denotes a descendant type wildcard.
The @* wildcard matches all attribute nodes. For example, this XSLT template rule copies the values of all attributes of a person element in the document into the content of an attributes element in the output: <xsl:template match="person"> <attributes><xsl:apply-templates select="@*"/></attributes> </xsl:template> ...
Use:
//a[@id[starts-with(., 'foo') and string-length() > 3]]
Not a wildcard, but probably what you need nonetheless:
//a[(@id!='foo') and starts-with(@id,'foo')]
See W3C XPath spec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With