"> ">
Download presentation
Presentation is loading. Please wait.
Published byGeoffrey Sullivan Modified over 9 years ago
1
XML Data Management XSLT Exercises: Right or Wrong? Werner Nutt
2
Transform 4: Task 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.
3
Transform 4: Solution 1 <xsl:sort select=".[../name() = 'director' and (name()='first_name' or name()='last_name')]/name()"/>
4
Transform 7: Task Return an element “actors” with a list of “actor” elements, alphabetically sorted by last name and first name, where each actor from the movies document occurs exactly once. Each actor element should contain last name, first name, and year of birth of the actor. Hint: You may need an element to remember the last name when you sort according to first name.
5
Transform 7: Solution 1/1
6
Transform 7: Solution 1/2 <xsl:if test="not(./last_name = preceding::actor/last_name and./first_name = preceding::actor/first_name)">
7
Transform 7: Solution 2 <xsl:variable name="firstname" select="string(./first_name)"/> <xsl:if test="not(string(./last_name) = preceding::actor[first_name=$firstname]/last_name)">
8
Transform 7: Solution 3 <xsl:key name="actor-by-name-dob" match="actor" use="concat(last_name, '+', first_name, '+', birth_date)"/> <xsl:for-each select="//actor[generate-id() = generate-id(key('actor-by-name-dob', concat(last_name, '+', first_name, '+', birth_date))[1])]">
9
Transform 8 Extend the stylesheet for the preceding task so that an actor also contains an element “movies” with the movies starring the actor (title and year are all the info needed for a movie)
10
Transform 8: Solution 1 <xsl:if test="not(./last_name = preceding::actor/last_name and./first_name = preceding::actor/first_name)">
11
Transform 8: Solution 2/1 <xsl:key name="actors-by-name" match="actor" use="last_name"/>
12
Transform 8: Solution 2/2
13
Transform 8: Solution 2/3
14
Transform 8: Solution 2/3 improved <xsl:for-each select="//movie[actor/last_name=$actor/last_name] [actor/first_name=$actor/first_name]">
15
Transform 8: Solution 2/3 improved again <xsl:for-each select="//movie[actor[last_name=$actor/last_name] [first_name=$actor/first_name]]">
16
Transform 8: Solution 3 <xsl:key name="actor-by-name-dob" match="actor" use="concat(last_name, '+', first_name, '+', birth_date)"/>
17
Transform 8: Solution 3/2 <xsl:for-each select="//actor[generate-id() = generate-id(key('actor-by-name-dob', concat(last_name, '+', first_name, '+', birth_date))[1])]"> <xsl:for-each select="key('actor-by-name-dob', concat(last_name, '+', first_name, '+', birth_date))/..">
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.