A query with prolog and body
File: Data.xml
<order>
<car model="A">
<id>0001</id>
<name language="en">name 1</name>
</car>
<car model="B">
<id>0002</id>
<name language="en">name 2</name>
</car>
<car model="B">
<id>0003</id>
<name language="en">name 3</name>
</car>
</order>
File: Query.xquery
declare boundary-space preserve;
declare namespace prod = "http://java2s.com/prod";
declare variable $order := doc("Data.xml")//order;
<firstResult>{count($order/car)}</firstResult>,
<prod:secondResult>{$order/car/id}</prod:secondResult>
Output:
<?xml version="1.0" encoding="UTF-8"?>
<firstResult>3</firstResult>
<prod:secondResult xmlns:prod="http://java2s.com/prod">
<id>0001</id>
<id>0002</id>
<id>0003</id>
</prod:secondResult>
Related examples in the same category