Our second XQuery homework exercise works with our Digital Mitford project files, coded in TEI. Here’s how to locate this collection in our newtfire eXist-db: collection('/db/mitford').

IMPORTANT: You’ll need to declare the TEI namespace at the top of any XQuery you run on these TEI files or you won’t see any output. (Declare the namespace in the line just under xquery version "3.1";). Here’s the line you need for that:

declare default element namespace "http://www.tei-c.org/ns/1.0";

Write XQuery expressions for each of the following tasks. Paste these into a text file or a document, and where we ask you to do so, record your return or output. Save your file using our standard homework filenaming conventions (as in besheroXQuery2.txt), and upload your assignment to Courseweb.

  1. First, let’s do some exploring. This is a large collection of files, so we might want to look at a complete list of their file names and get a count of the number of files. For this, we use the XPath function base-uri(). Write a statement in XQuery that returns the base-uri() (or filename) for each file in the Mitford collection. How many files are there? (Record the number.) Wrap the expression in a count() function so you return the number, and record the expression you used.
  2. Starting from the collection(), write a basic XQuery expression to show you the coding of the files, using /*, so that you can see how to locate the <title> element inside the <teiHeader> and <titleStmt>. Copy this into your text file recording this homework exercise.
  3. Begin working on FLWOR expressions. First, write a very simple FLWOR statement to define variables that will return the following:
  4. Build on your FLWOR expression. We are looking for some very important personal contacts of Mitford whose names turn up in the //body of more than 15 files in the Digital Mitford collection. Note:
  5. Finally, we will build an HTML file around your XQuery results using curly braces { } where necessary. Consult our XQuery Intro Guide on building HTML with Curly Braces. We need to make some changes to our file, though, because we are working with two different namespaces now, HTML and TEI. Alter the top lines of the XQuery so they look like this:
                xquery version "3.1";
    declare default element namespace "http://www.w3.org/1999/xhtml";
    declare namespace tei="http://www.tei-c.org/ns/1.0";
     
             
    And begin building your HTML around your FLWOR so the basic outermost structure of the file is set:
       xquery version "3.1";
    declare default element namespace "http://www.w3.org/1999/xhtml";
    declare namespace tei="http://www.tei-c.org/ns/1.0";
      <html>
    <head><title>Top Ten Most Referenced People in the Digital Mitford Project</title></head>
    <body>
        
            
    {
    . . . FLWOR HERE. . . 
    [use the tei:prefix on any TEI element names here]
    Return $something
    
    }
    </body>
    </html>   
    
  6. Build an HTML table in the HTML body part of the file to contain table rows and two columns of cells (two cells side by side in each column).
  7. Bonus: Instead of using string-join() to list out the multiple filenames in your second table cell, can you work out how to output that list of names in its own table, nested inside that second table cell? Inside the table cell, you will need to nest a new FLWOR statement inside a new set of curly braces, in which you’ll make another for statement. Return your output in table rows with a single column of cells.

Copy your HTML and FLWOR constructions into your document to upload to Courseweb.