=========================== XQuery Queries over Movies =========================== 1. Return an element "movie_titles" that contains a list of alphabetically sorted titles of all movies in the document ------------------------------------------------------------------------- ------------------------------------------------------------------------- 2. Modify the code so that each movie title has an attribute "number", indicating the position of the title on the list. ------------------------------------------------------------------------- ------------------------------------------------------------------------- 3. Return an element "movies" with a list of movie elements, containing in turn attributes title and year, ordered by year in descending order. Write two versions, one with static and one with dynamic attribute and element constructors. ------------------------------------------------------------------------- ------------------------------------------------------------------------- 4. Restructure the document so that - movies appear according to their year, with the most recent years first, and, within the same year, according to their title - countries appear in alphabetical order - for each director, the first name is given before the last name - actors of a movie appear according to their last name and, for actors with the same last name, according to their first name Everything else should remain as before. ------------------------------------------------------------------------- ------------------------------------------------------------------------- 5. Restructure the document so that movies are ordered according to their genre. That is, below the node movies, there should be several genre elements, one for each of the genres occurring in the document, with an attribute name indicating the name of the genre. Below each genre element, there should be the movies of that genre. Each movie should be structured as for the previous problem, except that there should not be a genre element in the movie. ------------------------------------------------------------------------- ------------------------------------------------------------------------- 6. Output movies (title and year) and within each movie those actors whose role occurs in the summary of the movie. ------------------------------------------------------------------------- ------------------------------------------------------------------------- 7. Return an element "actors" that contains for each actor occurring in the document one element actor with attributes first_name, last_name, yob (= year of birth) and an element "film" with attributes title and year and element role, where the films are ordered according to year. Note that for each actor in the input document, there should be exactly one actor in the output. Make sure your code works also if you have to actors with the same last name, say "Fred Smith" and "John Smith", that is, "Fred Smith" should appear before "John Smith". ------------------------------------------------------------------------- ------------------------------------------------------------------------- 8. Rewrite the code produced under 7. by introducing functions: declare function local:create-actor( $ln as xs:string, $fn as xs:string, $ms as element()*) as element(), which takes as input two strings, the last name and the first name of the actor, and a list of movies, returning the actor element for the actor with that name, declare function local:create-film-with-role( $m as element(), $ln as xs:string, $fn as xs:string) as element(), which takes a movie and two strings, the last name and the first name of the actor, returning a film element and with the role played by the actor. ------------------------------------------------------------------------- ------------------------------------------------------------------------- 9. Modify the code so that every actor has an attribute id and the values of id are integers running from 1 to the total number of actors. Hint: Introduce a function declare function local:sorted-actor-names ( $as as element()*) as element()* that takes a sequence of elements as input and outputs a sorted list of elements of the form . Use this sequence to produce a numbered sequence with the functions you have crated before. ------------------------------------------------------------------------- ------------------------------------------------------------------------- 10. Write XQuery code that disentangles movies, directors and actors in the folowing way. The result document has a top element cinema with two child elements, artists and movies. Below artists, there are artist elements and below movies there are movie elements. An artist has an id attribute, with a unique id, and subelements last_name, first_name, and birth_year. A movie element has the same kind of children as before, except for two changes - a director element has an attribute director_id, with the id of the artist who directed the film, and no child elements - an actor element has an attribute actor_id, with the id of the artist who acted in the film, and a child element, role as before. The XQuery code should take as input a document satisfying the movies DTD and output a document satisfying the description above. ------------------------------------------------------------------------- -------------------------------------------------------------------------