Let’s continue working with our Disney Songs project team’s collection of XML files in our newtfire eXist-dB that we explored in XQuery Exercise 3. Copy your queries into a text or markdown file in response to this exercise so you can submit them on Canvas.
(If you need to work with this on your local computer and prefer to use oXygen, the collection is stored in our textAnalysis-Hub at Class-Examples >> XQuery >> disneySongs. Please copy the directory to your own space (such as your own GitHub repo), and write your queries over it from oXygen.)
On newtFire’s eXist, the Disney Songs collection is stored in this filepath '/db/disneySongs/'
, so we can access it with:
collection('/db/disneySongs/')//*
Just as a reminder of the XML structure for this project, here is a short sample file:
<xml> <metadata> <title> One Jump Ahead (Reprise 2)</title> <origin>Lyrics from <movie>Aladdin (Live-Action)</movie> </origin> <author>Music by <composer ref="#Menken">Alan Menken</composer> Lyrics by <lyricist ref="#Pasek">Benj Pasek</lyricist> and <lyricist ref="#Paul">Justin Paul</lyricist> </author> <perform>Performed by <voiceActor ref="#Massoud" role="#Aladdin">Mena Massoud</voiceActor> as Aladdin</perform> </metadata> <song> <lg n="1"> <ln n="1"> Riffraff! Street rat! Would they think that</ln> <ln n="2">If they look much closer</ln> <ln n="3">Still, I can't play a prince here</ln> <ln n="4">No, siree</ln> </lg> <lg n="2"> <ln n="1">Gotta tell the truth</ln> <ln n="2">I can't pretend</ln> <ln n="3">Even if it means this dream will end</ln> <ln n="4">Even if she walks away from me</ln> </lg> </song> </xml>
For this assignment, let’s generate HTML as our XQuery output, instead of just concatenated strings of text. As modeled in class, we will be writing an HTML file around our XQuery code and using curly braces to wrap around the parts that need to be activated as XQuery. Here is a model of how to structure this code if you wanted to create an HTML document containing a table. In the model code below, notice:
<tr>
) with special table heading elements (<th>
) to sit at the top of the table,<tr>
element for each turn of its for loop. Inside that <tr>
, we use HTML table data elements (<td>
) to return the value of the XQuery variables from the for loop, a composer name and the titles associated with that composer. This code is saved in our newtfire eXist-dB, and you can find and run it (using Eval) in db/2023-Class-Examples/ or just view its results as HTML code.
xquery version "3.1"; <html> <head><title>Composers and Songs</title></head> <body> <h1>Composers and Songs in the Disney Songs Collection</h1> <table> <tr><th>No.</th><th>Composers</th><th>Performers</th><th>List of Songs</th></tr>{
let $disneySongs := collection('/db/disneySongs/') let $composers := $disneySongs//composer ! normalize-space() => distinct-values() => sort() for $c at $pos in $composers let $cTitles := $disneySongs[.//composer ! normalize-space() = $c]//title ! normalize-space() => distinct-values() => sort() => string-join(', ') return <tr> <td>{$pos}
</td><td>{$c}
</td><td>{$cTitles}
</td> </tr>}
</table> </body> </html>
Your task with this assignment is to explore the Disney Songs collection metadata in some way different from what we did in class. You must not simply return a list of composers and their associated song titles. What other combinations can you explore? What if you looped through a distinct list of movie titles and listed song titles, and/or the composers or voice actors associated with each?
Your output could be in the form of an HTML with a set of nested lists, or a table like we set here. Use w3schools to help you with the HTML output format you need to set up. You can copy and and paste your XQuery code as usual into an text or markdown file. If you worked on this in oXygen, you can save your HTML output to an HTML file (use a .html
extension). As we work with eXist-dB locally or with login access on my newtfire eXist-dB, you will be able to save your output, but we will go over this in class next time! In the meantime, submitting a screen capture of your output is okay, or just the XQuery of your code itself. The XQuery is the only file you need to submit for this exercise, but feel free to send output or a screen capture of it if you are able to do so! Upload your file containing your XQuery to Canvas (and sending a view of the output is optional).