TASK 1:
iTunes is an application from Apple to manipulate and store media files. The application stores the information from the media files in an XML file, which DTD can be found here: . Create an XML Schema that represents the same structure with appropriate data types for easier validation.
SOLUTION:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" elementFormDefault = "qualified">
<xsd:element name = "plist">
<xsd:complexType>
<xsd:group ref="plistObject"></xsd:group>
<xsd:attribute name = "version" type = "xsd:string" default="1.0"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="array">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:group ref="plistObject"></xsd:group>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="dict">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="key" type="xsd:string"></xsd:element>
<xsd:group ref="plistObject"></xsd:group>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:group name="plistObject">
<xsd:choice>
<xsd:element ref="array"></xsd:element>
<xsd:element name="string" type="xsd:string"></xsd:element>
<xsd:element name="data" type="xsd:base64Binary"></xsd:element>
<xsd:element name="date" type="xsd:dateTime"></xsd:element>
<xsd:element ref = "dict"/>
<xsd:element name="real" type="xsd:decimal"></xsd:element>
<xsd:element name="integer" type="xsd:integer"></xsd:element>
<xsd:element name="true" ></xsd:element>
<xsd:element name="false" ></xsd:element>
</xsd:choice>
</xsd:group>
</xsd:schema>
-----------------------------------------------------------------------------
TASK 2:
Create an XSLT file that transforms a given XML library from iTunes into your new schemata.
SOLUTION:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" version="1.0"/>
<xsl:template match="/">
<plist version="1.0"
xsi:noNamespaceSchemaLocation="ITunes Schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:call-template name="plist"></xsl:call-template>
</plist>
</xsl:template>
<xsl:template match="plist" name="plist">
<xsl:copy-of select="plist/*"/>
</xsl:template>
</xsl:stylesheet>
-----------------------------------------------------------------------------
TASK 3:
Create an XSLT file that transforms the iTunes XML library into a human-readable XHTML 1.0 Strict file with adequate CSS styling.
SOLUTION:
1. Create an XSLT file and write the following code;
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<Title>My ITunes collection</Title>
</head>
<link rel="stylesheet" type="text/css" href="iTunesStyleSheet.css"/>
<body>
<h1>My iTunes collection</h1>
<xsl:call-template name="plist"></xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template name="plist">
<xsl:if test="plist/dict/key[. = 'Application Version']">
<h2>
(Application Version: <xsl:value-of select="plist/dict/key[. = 'Application Version']/following-sibling::*/text()"/>)
</h2>
<h3 style="text-align:right">© Copyright 2011, Muhammad Salman Malik</h3>
<!--Playlist Information in the xml-->
<table border="0" style="width:100%">
<tr>
<th style="width:20%">Name</th>
<th style="width:20%">Artist</th>
<th style="width:20%">Album</th>
<th style="width:20%">Genre</th>
<th style="width:20%">Time</th>
</tr>
<xsl:for-each select="plist/dict/dict/dict">
<xsl:sort select="key[. = 'Name']/following-sibling::*/text()"/>
<tr>
<xsl:if test="position() mod 2 != 1">
<xsl:attribute name="style">
background-color:#EEEEEE
</xsl:attribute>
</xsl:if>
<td >
<img src="itunes play.jpg" longdesc="my ITunes collection"></img>
<a>
<xsl:attribute name="href">
<xsl:value-of select="key[. = 'Location']/following-sibling::*/text()"/>
</xsl:attribute>
<xsl:value-of select="key[. = 'Name']/following-sibling::*/text()"/>
</a>
</td>
<td>
<xsl:value-of select="key[. = 'Artist']/following-sibling::*/text()"/>
</td>
<td>
<xsl:value-of select="key[. = 'Album']/following-sibling::*/text()"/>
</td>
<td>
<xsl:value-of select="key[. = 'Genre']/following-sibling::*/text()"/>
</td>
<td>
<xsl:apply-templates select="key[. = 'Total Time']" mode="time"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
</xsl:template>
<xsl:template match="key" mode="time">
<xsl:variable name="mytime" select="following-sibling::*/text()"/>
<xsl:value-of select="floor ($mytime div 60000)"/>:
<xsl:value-of select="floor((($mytime div 60000) - floor ($mytime div 60000)) * 60)"/>
</xsl:template>
</xsl:stylesheet>
2. Create a CSS file and write the following code;
h1 {
text-align:center;
font-family:arial;
font-size:22pt;
color:#3B3B3B;
}
h2 {
text-align:center;
font-family:arial;
font-size:10pt;
color:#3B3B3B;
}
h3 {
text-align:center;
font-family:arial;
font-size:8pt;
color:#3B3B3B;
}
table {
border-style:none;
padding:0px;
margin:0px;
text-align:left;
}
th {
font-family:arial;
font-size:14pt;
background-color:#3B3B3B;
color:#FFFFFF;
}
tr{
font-weight:normal;
}
td {
font-family:arial;
font-size:11pt;
color:#7F7F7F;
}
a:link {
text-decoration:none;
color:#7F7F7F;
}
a:hover {
font-weight:bold;
text-decoration:none;
color:#3B3B3B;
}
a:visited {
text-decoration:none;
color:#333333;
}
It should look like as it is shown in the following image;

iTunes is an application from Apple to manipulate and store media files. The application stores the information from the media files in an XML file, which DTD can be found here: . Create an XML Schema that represents the same structure with appropriate data types for easier validation.
SOLUTION:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema" elementFormDefault = "qualified">
<xsd:element name = "plist">
<xsd:complexType>
<xsd:group ref="plistObject"></xsd:group>
<xsd:attribute name = "version" type = "xsd:string" default="1.0"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="array">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:group ref="plistObject"></xsd:group>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="dict">
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="key" type="xsd:string"></xsd:element>
<xsd:group ref="plistObject"></xsd:group>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:group name="plistObject">
<xsd:choice>
<xsd:element ref="array"></xsd:element>
<xsd:element name="string" type="xsd:string"></xsd:element>
<xsd:element name="data" type="xsd:base64Binary"></xsd:element>
<xsd:element name="date" type="xsd:dateTime"></xsd:element>
<xsd:element ref = "dict"/>
<xsd:element name="real" type="xsd:decimal"></xsd:element>
<xsd:element name="integer" type="xsd:integer"></xsd:element>
<xsd:element name="true" ></xsd:element>
<xsd:element name="false" ></xsd:element>
</xsd:choice>
</xsd:group>
</xsd:schema>
-----------------------------------------------------------------------------
TASK 2:
Create an XSLT file that transforms a given XML library from iTunes into your new schemata.
SOLUTION:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" version="1.0"/>
<xsl:template match="/">
<plist version="1.0"
xsi:noNamespaceSchemaLocation="ITunes Schema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:call-template name="plist"></xsl:call-template>
</plist>
</xsl:template>
<xsl:template match="plist" name="plist">
<xsl:copy-of select="plist/*"/>
</xsl:template>
</xsl:stylesheet>
-----------------------------------------------------------------------------
TASK 3:
Create an XSLT file that transforms the iTunes XML library into a human-readable XHTML 1.0 Strict file with adequate CSS styling.
SOLUTION:
1. Create an XSLT file and write the following code;
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<Title>My ITunes collection</Title>
</head>
<link rel="stylesheet" type="text/css" href="iTunesStyleSheet.css"/>
<body>
<h1>My iTunes collection</h1>
<xsl:call-template name="plist"></xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template name="plist">
<xsl:if test="plist/dict/key[. = 'Application Version']">
<h2>
(Application Version: <xsl:value-of select="plist/dict/key[. = 'Application Version']/following-sibling::*/text()"/>)
</h2>
<h3 style="text-align:right">© Copyright 2011, Muhammad Salman Malik</h3>
<!--Playlist Information in the xml-->
<table border="0" style="width:100%">
<tr>
<th style="width:20%">Name</th>
<th style="width:20%">Artist</th>
<th style="width:20%">Album</th>
<th style="width:20%">Genre</th>
<th style="width:20%">Time</th>
</tr>
<xsl:for-each select="plist/dict/dict/dict">
<xsl:sort select="key[. = 'Name']/following-sibling::*/text()"/>
<tr>
<xsl:if test="position() mod 2 != 1">
<xsl:attribute name="style">
background-color:#EEEEEE
</xsl:attribute>
</xsl:if>
<td >
<img src="itunes play.jpg" longdesc="my ITunes collection"></img>
<a>
<xsl:attribute name="href">
<xsl:value-of select="key[. = 'Location']/following-sibling::*/text()"/>
</xsl:attribute>
<xsl:value-of select="key[. = 'Name']/following-sibling::*/text()"/>
</a>
</td>
<td>
<xsl:value-of select="key[. = 'Artist']/following-sibling::*/text()"/>
</td>
<td>
<xsl:value-of select="key[. = 'Album']/following-sibling::*/text()"/>
</td>
<td>
<xsl:value-of select="key[. = 'Genre']/following-sibling::*/text()"/>
</td>
<td>
<xsl:apply-templates select="key[. = 'Total Time']" mode="time"/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
</xsl:template>
<xsl:template match="key" mode="time">
<xsl:variable name="mytime" select="following-sibling::*/text()"/>
<xsl:value-of select="floor ($mytime div 60000)"/>:
<xsl:value-of select="floor((($mytime div 60000) - floor ($mytime div 60000)) * 60)"/>
</xsl:template>
</xsl:stylesheet>
2. Create a CSS file and write the following code;
h1 {
text-align:center;
font-family:arial;
font-size:22pt;
color:#3B3B3B;
}
h2 {
text-align:center;
font-family:arial;
font-size:10pt;
color:#3B3B3B;
}
h3 {
text-align:center;
font-family:arial;
font-size:8pt;
color:#3B3B3B;
}
table {
border-style:none;
padding:0px;
margin:0px;
text-align:left;
}
th {
font-family:arial;
font-size:14pt;
background-color:#3B3B3B;
color:#FFFFFF;
}
tr{
font-weight:normal;
}
td {
font-family:arial;
font-size:11pt;
color:#7F7F7F;
}
a:link {
text-decoration:none;
color:#7F7F7F;
}
a:hover {
font-weight:bold;
text-decoration:none;
color:#3B3B3B;
}
a:visited {
text-decoration:none;
color:#333333;
}
It should look like as it is shown in the following image;
