Based on past papers, the XQuery question seems to take the exact same format every year, hence, the answers can be memorised and specified to apply to the current question.


Most Recent Sample Paper

For the XML:

<BankRegistery>
	<Bank BankID=”1” Classification=”community” >
		<BankName>Allied Irish Bank</BankName>
		<BankManager>
			<title>Ms</title>
			<firstname>Sarah</firstname>
			<lastname>Greene</lastname>
		</BankManager>
		<Branch BranchID=”10” CounterService = “No”>
			<Name>AIB Ranelagh</Name>
			<NoOfATM>3</NoOfATM>
		</Branch>
		<Branch BranchID= ”2” CounterService=”yes”>
			<Name>AIB Crumlin</Name>
			<NoOfATM>1</NoOfATM>
		</Branch>
	</Bank>
		  
	<Bank BankID=”2” Classification="Commercial">
		<BankName>CitiBank Europe</BankName>
		<BankManager>
			<title>Mr</title>
			<firstname>Thomas</firstname>
			<firstname>Harry</firstname>
			<lastname>Duffy</lastname>
		</BankManager>
			<Branch BranchID ="5" CounterService =”no”>
			<Name>CitiBank Dublin</Name>
			<NoOfATM/>
		</Branch>
	</Bank>
 
	<Bank BankID =”3”>
		<BankName>Bank Of Ireland</BankName>
		<BankManager>
			<firstname>Jean</firstname>
			<lastname>Murphy</lastname>
		</BankManager>
	</Bank>
</BankRegistery>

The following XQuery question was posed:

Question

Write XQuery Statements for each of the following queries posed on the document in Figure B. Show the results that you would expect to get when you run the query.

  1. Return all of the values of the BankName elements in the document separated by a ”+” sign.
  2. In a new element called BankClassifications, return the values of any Classification attributes that appear in the document.
  3. Return only the first of the firstname elements for each BankManager in the document.
  4. For the Bank with BankID , return within an element called BankDetails the element BankName and all of the elements in the BankManager element.

Note

To avoid having to load the document repeatedly we will specify that we have a global let statement applying for all the questions.

This takes the form:

let $bankRegistry := doc("banks.xml")

Question

  1. Return all of the values of the BankName elements in the document separated by a ”+” sign.

XQuery:

string-join(bankRegistry//BankName, "+")

Expected Result:

Allied Irish Bank+CitiBank Europe+Bank Of Ireland

Question

  1. In a new element called BankClassifications, return the values of any Classification attributes that appear in the document.

XQuery:

<BankClassifications>{
	for $classification in bankRegistry//@Classification
	return <Classification>{$classification}</Classification>
}</BankClassifications>

Expected Result:

<BankClassifications>
	<Classification>community</Classification>
	<Classification>Commercial</Classification>
</BankClassifications>

Question

  1. Return only the first of the firstname elements for each BankManager in the document.

XQuery:

for $manager in bankRegistry//BankManager
return $manager/firstname[1]

Expected Result:

<firstname>Sarah</firstname>
<firstname>Thomas</firstname>
<firstname>Jean</firstname>

Question

  1. For the Bank with BankID , return within an element called BankDetails the element BankName and all of the elements in the BankManager element.

XQuery:

for $bank in bankRegistry//Bank
where $bank/@BankID = "2"
return 
	<BankDetails>
		{$bank/BankName}
		{$bank/BankManager/*}
	</BankDetails>

Expected Result:

<BankDetails> 
	<BankName>CitiBank Europe</BankName> 
	<title>Mr</title> 
	<firstname>Thomas</firstname> 
	<firstname>Harry</firstname> 
	<lastname>Duffy</lastname> 
</BankDetails>