Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • How I could do same for //bookstore/book[@location='US'] ? Commented Mar 11, 2011 at 19:04
  • 7
    This will get all books from 'US'. (/bookstore/book[@location='US'])[1] will get the first one. Commented Apr 17, 2012 at 19:39
  • 3
    @KevinDriedger /bookstore/book[@location='US'][1] does not return all books from 'US'. I have tested it mutiple times and under different languages' xpath implementations. /bookstore/book[@location='US'][1] returns the first 'US' book under a bookstore. If there are mutiple bookstores, then it will return the first from each. This is what the OP asked for (the first node under bookstore). Your version returns only one book from all bookstores (the first match). Commented Apr 18, 2012 at 18:38
  • 3
    @JonathanFingland you misunderstood - read KevinDriedger's answer again, along with context of AlexanderV.Ilyin's question. You both mean the same thing. Commented Apr 5, 2016 at 6:27