You can use "//*[firstname='Sheila' and position() <= 100] "
Edit:
Given the following XML:
<root> <country.php desc="country.php" language="fr|pt|en|in" editable="Yes"> <en/> <in> <cityList desc="cityList" language="in" editable="Yes" type="Array" index="No"> <element0>Abu</element0> <element1>Agartala</element1> <element2>Agra</element2> <element3>Ahmedabad</element3> <element4> Ahmednagar</element4> <element5>Aizwal</element5> <element150>abcd</element150> </cityList> </in> </country.php> </root>
You can use the following XPath to get the first three cities:
Results:
Node element0 Abu Node element1 Agartala Node element2 Agra
If you want to limit this to nodes starting with element :
//cityList/*[substring(name(), 1, 7) = 'element' and position()<=3]
Note that this last example works because you select all cityList child nodes, so in this case Position() works to limit the results as expected. If there was a combination of other node names in the cityList node list, you would get unwanted results.
For example, changing the XML as follows:
<root> <country.php desc="country.php" language="fr|pt|en|in" editable="Yes"> <en/> <in> <cityList desc="cityList" language="in" editable="Yes" type="Array" index="No"> <element0>Abu</element0> <dog>Agartala</dog> <cat>Agra</cat> <element3>Ahmedabad</element3> <element4> Ahmednagar</element4> <element5>Aizwal</element5> <element150>abcd</element150> </cityList> </in> </country.php> </root>
and using the above XPath expression, now we get
Node element0 Abu
Note that we lose the second and third results, because the Position() function evaluates in a higher priority order - the same as the request "give me the first three nodes, now from them give me all the nodes that start with" item. "
Geoff
source share