Multiple choice technology web technology

How do you select the first two titles in the document:

  1. a. (//title)[order()<=2]

  2. b. (//title)[index()<=2]

  3. c. (//title)[last()<=2]

  4. d. (//title)[position()<=2]

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

To select the first two title elements in an XML document using XPath, you use (//title)[position()<=2]. The position() function returns the current node's position number, and the predicate filters to keep only the first two. Option A uses order() which doesn't exist in XPath, option B uses index() which is not standard XPath, and option C uses last() which would only match if there were 2 or fewer titles total.