NewtFire logo: a mosaic rendering of a firebelly newt
newtFire {dh|ds}
Maintained by: Elisa E. Beshero-Bondar (ebb8 at Creative Commons License Last modified: Monday, 19-Feb-2018 07:38:37 UTC. Powered by firebellies.

For our first XQuery exercise we’ll be working with a collection of Shakespeare’s plays (actually not coded in TEI). We have uploaded these into our eXist XML database, and you can locate them in this collection: collection('/db/shakespeare/plays')

Write XQuery expressions for each of the following tasks using the eXide window in our eXist database, and test them by hitting the Eval button. Then paste your XQuery expressions into a text file, adding comments as needed. You will be submitting your text file to Courseweb.

  1. Find all of the titles of all of the Shakespeare plays in the collection. You will need to read our Guide to XQuery and eXist for information about how to address the collection of plays. The Guide will also help you figure out how to retrieve the full text of one of the plays so that you can look at it and see where the <TITLE> element is, which you will need to know in order to construct the XPath to retrieve it. The simplest answer is a single XPath expression. The output should look something like:
                   <TITLE>The Tragedy of Hamlet, Prince of Denmark</TITLE> 
                   <TITLE>The Tragedy of Macbeth</TITLE> 
                   <TITLE>The Tragedy of Romeo and Juliet</TITLE>
  2. Modify your XPath above to return just the text of the titles, without the tags. You can do that by using text() or data() or string() . Your output should look something like:
                   The Tragedy of Hamlet, Prince of Denmark
                   The Tragedy of Macbeth
                   The Tragedy of Romeo and Juliet
  3. Find the play that contains a count of more than 40 unique (distinct) speakers and then return its <TITLE> element. You will need to use count() and distinct-values(), and you’ll need a construction involving count(of something) gt 40 .

    Find the collection, drill down to the <PLAY> elements in the collection (you know there are three of them), then filter them based on whether or not they contain more than 40 <SPEAKER> elements. Once you’re getting the one play that meets that description, you can add a path step to retrieve its <TITLE>.

  4. FLWOR Statement or XPath expression?: Did you write your XQuery for number 4 with a long XPath expression (from left to right)? Or did you write it up as a FLWOR statement? (Review our tutorial for details and examples on writing FLWOR statements using variables.) Whichever way you chose to write your XQuery in the previous steps, try the other way and see if you can duplicate your results. Record your XQuery expressions in your text file.

When you have completed the assignment upload your text file containing your XQuery expressions to Courseweb.