Wikibooksβ

XQuery/Example Sequencer

The code examples used in the XQuery /SQL comparison are coded in an XML file. The WikiBook page redundantly has the code pasted into the page but an alternative is to provide an application to generate the whole page together with the executed examples from the XML script.

Here is a sample of the XML script:

<Query id="30">
<Task>List the name of each employee together with the name of their manager.</Task>
<MySQL>select e.ename, m.ename
from emp e, emp m
where e.mgr = m.empno ;</MySQL>
<XQuery><![CDATA[for $emp in //Emp
let $manager := //Emp[EmpNo = $emp/MgrNo]
return
<Emp>
{$emp/Ename}
<Manager>{string($manager/Ename)}</Manager>
</Emp>
]]></XQuery>
<Comment>The SQL Join has missed Employee King who has no manager,</Comment>
</Query>

To allow the queries to be executed in a selected order, a lesson defines a sequence of queries: