CS 582 — Database Management System II — Spring 2007

Quiz #9

NAME:

Suppose that we have two XML documents, the transcript XML and the professor XML document. The transcript XML document resides at http://test.xml/transcript.xml and looks like the following:

... preamble of XML documents ...
<students>
<student ID=''s123''>
<Name> John Murphy </Name>
<Class Code=''CS123'' Semester=''F2002'' Grade=''A''/>
<Class Code=''CS234'' Semester=''S2003'' Grade=''B''/>
<Class Code=''CS235'' Semester=''F2003'' Grade=''C''/>
<Class Code=''CS400'' Semester=''F2003'' Grade=''D''/>
</student>
<student ID=''s124''>
<Name> Harry Son  </Name>
<Class Code=''CS123'' Semester=''F2002'' Grade=''C''/>
<Class Code=''CS234'' Semester=''S2003'' Grade=''B''/>
<Class Code=''CS235'' Semester=''S2003'' Grade=''B''/>
<Class Code=''CS400'' Semester=''F2003'' Grade=''C''/>
</student>
...
</students>

The professor XML document resides at http://test.xml/profs.xml and looks like the following:

... preamble of XML documents ...
<professors>
<professor ID=''p123''>
<Name> John Little </Name>
<Class Code=''CS123'' Semester=''F2002''/>
<Class Code=''CS234'' Semester=''S2003''/>
</student>
<professor ID=''p125''>
<Name> Marry Parpet </Name>
<Class Code=''CS235'' Semester=''F2003''/>
<Class Code=''CS235'' Semester=''S2003''/>
<Class Code=''CS400'' Semester=''F2003''/>
</student>
...
</professors>

We assume that each class is taught by only one professor. Write a XQuery statement that attaches the name of the professor to each class of the student in the transcript XML document (below is an example of the first student):

....
<students>
<student ID=''s123''>
<Name> John Murphy </Name>
<Class Code=''CS123'' Semester=''F2002'' Grade=''A''>
   <Prof> John Little </Prof>
</Class>
<Class Code=''CS234'' Semester=''S2003'' Grade=''B''>
   <Prof> John Little </Prof>
</Class>
<Class Code=''CS235'' Semester=''F2003'' Grade=''C''>
   <Prof> Marry Parpet </Prof>
</Class>
<Class Code=''CS400'' Semester=''F2003'' Grade=''D''>
   <Prof> Marry Parpet </Prof>
</Class>
</student>
...
</students>