Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should be able to use <code>"//*[firstname='Sheila' and position() &lt;= 100]</code>"</p> <p><strong>Edit:</strong></p> <p>Given the following XML:</p> <pre><code>&lt;root&gt; &lt;country.php desc="country.php" language="fr|pt|en|in" editable="Yes"&gt; &lt;en/&gt; &lt;in&gt; &lt;cityList desc="cityList" language="in" editable="Yes" type="Array" index="No"&gt; &lt;element0&gt;Abu&lt;/element0&gt; &lt;element1&gt;Agartala&lt;/element1&gt; &lt;element2&gt;Agra&lt;/element2&gt; &lt;element3&gt;Ahmedabad&lt;/element3&gt; &lt;element4&gt; Ahmednagar&lt;/element4&gt; &lt;element5&gt;Aizwal&lt;/element5&gt; &lt;element150&gt;abcd&lt;/element150&gt; &lt;/cityList&gt; &lt;/in&gt; &lt;/country.php&gt; &lt;/root&gt; </code></pre> <p>You can use the following XPath to get the first three cities:</p> <pre><code>//cityList/*[position()&lt;=3] </code></pre> <p>Results:</p> <pre><code>Node element0 Abu Node element1 Agartala Node element2 Agra </code></pre> <p>If you want to limit this to nodes that start with <code>element</code>:</p> <pre><code>//cityList/*[substring(name(), 1, 7) = 'element' and position()&lt;=3] </code></pre> <p>Note that this latter example works because you're selecting <em>all</em> the child nodes of cityList, so in this case <code>Position()</code> works to limit the results as expected. If there was a mix of other node names under the cityList node, you'd get undesirable results.<br> For example, changing the XML as follows:</p> <pre><code>&lt;root&gt; &lt;country.php desc="country.php" language="fr|pt|en|in" editable="Yes"&gt; &lt;en/&gt; &lt;in&gt; &lt;cityList desc="cityList" language="in" editable="Yes" type="Array" index="No"&gt; &lt;element0&gt;Abu&lt;/element0&gt; &lt;dog&gt;Agartala&lt;/dog&gt; &lt;cat&gt;Agra&lt;/cat&gt; &lt;element3&gt;Ahmedabad&lt;/element3&gt; &lt;element4&gt; Ahmednagar&lt;/element4&gt; &lt;element5&gt;Aizwal&lt;/element5&gt; &lt;element150&gt;abcd&lt;/element150&gt; &lt;/cityList&gt; &lt;/in&gt; &lt;/country.php&gt; &lt;/root&gt; </code></pre> <p>and using the above XPath expression, we now get </p> <pre><code>Node element0 Abu </code></pre> <p>Note that we're losing the second and third results, because the <code>position()</code> function is evaluating at a higher order of precedence - the same as requesting "give me the first three nodes, now out of those give me all the nodes that start with 'element'".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload