XML - Managing Data Exchange/XLink/Exercises

XLink Chapter => XLink

XLink Answers => Answers

1) Movie Collection

edit

Modify the movie XML document from the many-to-many chapter to use XLink capabilities. Each movie title should be a displayed as an XLink to the movie's description located in "The Internet Movie Database" at http://www.imdb.com/.

the Schema

edit
<?xml version="1.0" encoding="UTF-8"?>
<!--
    Document   : movies.xsd
    Created on : February 6, 2006
    Author     : Christina Serrano
    Description: XML schema describing structure of movie collection
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified"> 
<xsd:element name="movieCollection">     
   <xsd:complexType>
      <xsd:sequence>
         <xsd:element name="movie" type="movieDetails" minOccurs="1" maxOccurs="unbounded"/>
         <xsd:element name="castMember" type="castDetails" minOccurs="1" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
</xsd:element>
   <xsd:complexType name="movieDetails">
      <xsd:sequence>
         <xsd:element name="movieTitle" type="xsd:string"/>
         <xsd:element name="movieSynopsis" type="xsd:string"/>
         <xsd:element name="role" type="roleDetails" minOccurs="1" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="roleDetails">
      <xsd:sequence>
         <xsd:element name="roleIDREF" type="xsd:IDREF"/>
         <xsd:element name="roleType" type="xsd:string"/>         
      </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="castDetails">
      <xsd:sequence>
         <xsd:element name="castMemberID" type="xsd:ID"/>
         <xsd:element name="castFirstName" type="xsd:string"/>
         <xsd:element name="castLastName" type="xsd:string"/>
         <xsd:element name="castSSN" type="ssnType" minOccurs="0"/>
         <xsd:element name="castGender" type="genderType"/>         
      </xsd:sequence>
   </xsd:complexType>
   <xsd:simpleType name="ssnType">
       <xsd:restriction base="xsd:string">
          <xsd:pattern value="\d{3}-\d{2}-\d{4}"/>
       </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="genderType">
       <xsd:restriction base="xsd:string">
          <xsd:enumeration value="male"/>
          <xsd:enumeration value="female"/>
       </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>

the Document

edit
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="movies.xsl" type="text/xsl" media="screen"?>
<!--
    Document   : movies.xml
    Created on : February 6, 2006
    Author     : Christina Serrano
    Description: XML document describing movie collection
-->
<movieCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="movies.xsd">   
   <movie>
        <movieTitle>City of God</movieTitle>
        <movieSynopsis>
          Youth gangs took over the slums of Rio de Janiero during the 1960s and didn't relinquish their 
          stronghold until the mid-1980s. Only a sucker wouldn't have turned to crime and this is exactly 
          how naive teen Rocket views himself. Rocket shoots all of the action with his weapon of choice, 
          a camera.
        </movieSynopsis>
        <role>
            <roleIDREF>ar1</roleIDREF>
            <roleType>Lead Actor</roleType>
        </role>
        <role>
            <roleIDREF>lf1</roleIDREF>
            <roleType>Lead Actor</roleType>
        </role>
        <role>
            <roleIDREF>kf1</roleIDREF>
            <roleType>Lead Actress</roleType>
        </role>   
   </movie>
   <movie>
        <movieTitle>Hotel Rwanda</movieTitle>
        <movieSynopsis>
          Paul Rusesabagina, the manager of a European-owned hotel in Rwanda, created a secret refugee camp 
          for the Tutsi people during the brutal genocide committed against them by the Hutu people in 1994. His 
          efforts helped to save 1200 lives out of close to a million who were killed.
        </movieSynopsis>
        <role>
            <roleIDREF>dc1</roleIDREF>
            <roleType>Lead Actor</roleType>
        </role>
        <role>
            <roleIDREF>nn1</roleIDREF>
            <roleType>Supporting Actor</roleType>
        </role>
        <role>
            <roleIDREF>so1</roleIDREF>
            <roleType>Lead Actress</roleType>
        </role>             
   </movie> 
   <movie>
        <movieTitle>Dodgeball</movieTitle>
        <movieSynopsis>
          The story's protagonist, Peter LaFleur, is a charismatic underachiever and proprietor of a rundown gym called
          Average Joe's. Peter's humble gym catches the eye of White Goodman, the power-mullet-sporting, Fu-Manchu-d, 
          egomaniacal owner of Globo Gym, a gleaming monolith of fitness. White intends to take over Average Joe's, and 
          Peter's non-existent bookkeeping is making it all too easy for him. The only way Peter can save Average Joe's 
          is a showdown dodgeball competition against Globo Gym.
        </movieSynopsis>
        <role>
            <roleIDREF>bs1</roleIDREF>
            <roleType>Lead Actor</roleType>
        </role>
        <role>
            <roleIDREF>ct1</roleIDREF>
            <roleType>Lead Actress</roleType>
        </role>
        <role>
            <roleIDREF>vv1</roleIDREF>
            <roleType>Lead Actor</roleType>
        </role>               
   </movie>
   <movie>
        <movieTitle>Meet the Parents</movieTitle>
        <movieSynopsis>
          Greg Focker is head over heels in love with his girlfriend Pam, and is ready to pop the big question. 
          When his attempt to propose is thwarted by a phone call with the news that Pam's younger sister is 
          getting married, Greg realizes that the key to Pam's hand in marriage lies with her formidable father. 
        </movieSynopsis>
        <role>
            <roleIDREF>bs1</roleIDREF>
            <roleType>Lead Actor</roleType>
        </role>
        <role>
            <roleIDREF>tp1</roleIDREF>
            <roleType>Lead Actress</roleType>
        </role>
        <role>
            <roleIDREF>rd1</roleIDREF>
            <roleType>Lead Actor</roleType>
        </role>            
   </movie>
    <castMember>
        <castMemberID>ar1</castMemberID>
        <castFirstName>Alexandre</castFirstName>
        <castLastName>Rodrigues</castLastName>
        <castSSN>867-34-2949</castSSN>
        <castGender>male</castGender>       
    </castMember>
    <castMember>
        <castMemberID>lf1</castMemberID>
        <castFirstName>Leandro</castFirstName>
        <castLastName>Firmino da Hora</castLastName>
        <castSSN>839-59-8765</castSSN>
        <castGender>male</castGender>       
    </castMember>
    <castMember>
        <castMemberID>kf1</castMemberID>
        <castFirstName>Karina</castFirstName>
        <castLastName>Falcao</castLastName>
        <castSSN>987-34-2958</castSSN>
        <castGender>female</castGender>       
    </castMember>
    <castMember>
        <castMemberID>dc1</castMemberID>
        <castFirstName>Don</castFirstName>
        <castLastName>Cheadle</castLastName>
        <castSSN>849-39-4439</castSSN>
        <castGender>male</castGender>       
    </castMember> 
    <castMember>
        <castMemberID>nn1</castMemberID>
        <castFirstName>Nick</castFirstName>
        <castLastName>Nolte</castLastName>
        <castSSN>233-56-4309</castSSN>
        <castGender>male</castGender>       
    </castMember>  
    <castMember>
        <castMemberID>so1</castMemberID>
        <castFirstName>Sophie</castFirstName>
        <castLastName>Okonedo</castLastName>
        <castSSN>993-23-4958</castSSN>
        <castGender>female</castGender>       
    </castMember>
    <castMember>
        <castMemberID>rd1</castMemberID>
        <castFirstName>Robert</castFirstName>
        <castLastName>De Niro</castLastName>
        <castSSN>489-32-5984</castSSN>
        <castGender>male</castGender>       
    </castMember> 
    <castMember>
        <castMemberID>bs1</castMemberID>
        <castFirstName>Ben</castFirstName>
        <castLastName>Stiller</castLastName>
        <castSSN>590-59-2774</castSSN>
        <castGender>male</castGender>       
    </castMember>
    <castMember>
        <castMemberID>tp1</castMemberID>
        <castFirstName>Teri</castFirstName>
        <castLastName>Polo</castLastName>
        <castSSN>099-37-8765</castSSN>
        <castGender>female</castGender>       
    </castMember>  
    <castMember>
        <castMemberID>vv1</castMemberID>
        <castFirstName>Vince</castFirstName>
        <castLastName>Vaughn</castLastName>
        <castSSN>383-56-2095</castSSN>
        <castGender>male</castGender>       
    </castMember>      
    <castMember>
        <castMemberID>ct1</castMemberID>
        <castFirstName>Christine</castFirstName>
        <castLastName>Taylor</castLastName>
        <castSSN>309-49-4005</castSSN>
        <castGender>female</castGender>       
    </castMember>              
</movieCollection>

the Stylesheet

edit
<?xml version="1.0" encoding="UTF-8"?>
<!--
    Document   : movies.xsl
    Created on : February 6, 2006
    Author     : Christina Serrano
    Description: XML stylesheet to format movie collection data
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:key name="castList" match="castMember" use="castMemberID"/>
    <xsl:output method="html"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>Movie Collection</title>
            </head>
            <body>
                <h2>Movie Collection</h2>
                <xsl:apply-templates select="movieCollection"/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="movieCollection">
        <xsl:for-each select="movie">
            <hr/>
            <br/>
            <b><xsl:text>Movie Title: </xsl:text></b>
            <xsl:value-of select="movieTitle"/>
            <br/>
            <br/>
            <b><xsl:text>Movie Synopsis: </xsl:text></b>            
            <xsl:value-of select="movieSynopsis"/>
            <br/>
            <br/>
            <b><xsl:text>Cast: </xsl:text></b>
            <br/>
            <xsl:for-each select="role">
                <xsl:value-of select="key('castList',roleIDREF)/castFirstName"/>
                 <xsl:text>   </xsl:text>
                <xsl:value-of select="key('castList',roleIDREF)/castLastName"/>               
                <xsl:text>,   </xsl:text>
                <xsl:value-of select="roleType"/>
                <br/>
                <xsl:value-of select="key('castList',roleIDREF)/castGender"/>
                <xsl:text>,   </xsl:text>
                <xsl:value-of select="key('castList',roleIDREF)/castSSN"/>
                <br/>
                <br/>
            </xsl:for-each>                     
        </xsl:for-each>       
    </xsl:template>
</xsl:stylesheet>



XLink Chapter => XLink

XLink Answers => Answers