5

Why is a comma used after the period in certain XPath expressions? Here is an example:

Set nlist = doc.selectNodes("//book/author/first-name[starts-with(.,'M')]")

I tried to search for this with Google, but the literal "" operators don't seem to like periods or commas.

Pops
  • 30,199
  • 37
  • 136
  • 151
NielsInc
  • 426
  • 7
  • 23
  • 1
    Period `.` is the abbreviated syntax version of `self::node()` – jasso May 30 '11 at 20:44
  • @jasso: current node (`self::node()`) is not the same as the context node (`.`). – Emiliano Poggi May 31 '11 at 05:35
  • @empo: As a *location step* `.` is same as `self::node()`, this is clearly stated in the XPath recommendation. `self::node()` is not (necessarily) the same node as returned by the XSLT function `current()`, if that is what you meant to refer to. – jasso May 31 '11 at 10:17

3 Answers3

3

starts-with has two parameters and returns true if the first parameter ends with the string from second parameter, otherwise it returns false.

If the first parameter is . it means the current item. You can find more about other XPath punctuation marks here.

jasso
  • 13,736
  • 2
  • 36
  • 50
Alex Aza
  • 76,499
  • 26
  • 155
  • 134
3

In XPath the . mark stands for context node. The context node is usually the same of the current node (current() function) being processed but it might be situations where it's different. This is not really obvious when you deal with XPath only, but it happens when using XSLT. See this question in SO explaining such a difference.

Community
  • 1
  • 1
Emiliano Poggi
  • 24,390
  • 8
  • 55
  • 67
  • Thanks for your answer. Is the dot a wildcard or a special keyword ? What are the other things we can pass to the function instead of the dot ? – MasterJoe Sep 22 '16 at 17:31
1

The . stands for "current node", the , is a normal parameter separator.

So, the parameters being sent to the starts-with function are a . (current node) and 'M'.

Oded
  • 489,969
  • 99
  • 883
  • 1,009