XQuery/Example Sequencer
< XQuery
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:
<Lesson id="t1"> <Name>Test Lesson 1</Name> <Step queryid="32"/> <Step queryid="33"/> <Step queryid="31"/> <Step queryid="21a"/> <Step queryid="20"/> </Lesson>
The user can step through the examples in the lesson :
Implementation
editTwo scripts form the core of this application, one to list the queries in a lesson, the other to execute the query code, both SQL and XQuery and show the results. ....