The output of the following query returns the five first city names of the <b>factbook</b> database:
<pre class="brush:xml">
<rest:query xmlns:rest="http://www.basex.org/rest"> <rest:text><![CDATA[ (//city/name)[position() <= 5] ]]></rest:text></rest:query>
</pre>
The second query returns the string lengths of all text nodes, which are found in the node that has been specified as initial context node:
<pre class="brush:xml">
<rest:query xmlns:rest="http://www.basex.org/rest"> <rest:text>for $i in .//text() return string-length($i)</rest:text> <rest:context>
<xml>
<text>Hello</text>
<text>World</text>
</xml>
</rest:context></rest:query>
</pre>