23

I'm using Firefox's XPath-checker and can't get the syntax right. I have a link:

<a>LinkName</a>

and I try doing:

//a[lower-case(child::text())='linkname']

but I have a syntax error. What am I doing wrong?

Thanks

Guy
  • 14,178
  • 27
  • 67
  • 88

2 Answers2

46

There is no function called lower-case in XPath 1.0 which is the version of XPath used in Firefox.

You need to use the ugly translate function instead:-

  translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')

...but of course you would need to extend this if you need coverage of a wider character-set.

Stoive
  • 11,232
  • 4
  • 24
  • 32
AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • 1
    Great hint - not only applicable to Firefox :) – Marcin Cylke Feb 16 '11 at 12:42
  • 1
    Note: "translate" should be lower-cased. – ThisGuyKnowsCode Apr 09 '12 at 16:18
  • 5
    Here is the complete ANSI table: translate(%s, 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ', 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ') – A.Game Feb 06 '15 at 09:31
  • Used it in my java code as `nodeRev = (NodeList) xPath.compile("//StandardDetail/IsReverseEvent[translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='true']").evaluate(doc, XPathConstants.NODESET);` – Pankaj Jaju Apr 28 '15 at 14:29
0

You can Use Translate

//a[translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'linkname']
Rayees
  • 57
  • 3
  • 15