|
|
 |
Try It Out - Using XSL Transformations
In this exercise, you are going to get a taste of things to come. Specifically, you are going to use the World Wide Web's new XSL Transformation technology to convert an XML document into two different presentations.
-
Run your text editor and type in the following:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title>Film Library:<xsl:value-of select="filmlibrary/name"/></title>
</head>
<body>
<table border="2">
<tr>
<td>Title</td>
<td>Director</td>
<td>Year</td>
<td>Genre</td>
</tr>
<xsl:for-each select="filmlibrary/movie">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="credits/director"/></td>
<td><xsl:value-of select="year"/></td>
<td><xsl:value-of select="genre"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
-
Save the file as movie1.xsl.
-
Create a new document in your text editor and type in the following:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="movie1.xsl"?>
<filmlibrary>
<name>Classic Films</name>
<movie>
<title>Beauty and the Beast</title>
<genre>Fantasy</genre>
<country>France</country>
<language>French</language>
<year>1946</year>
<length>90 Min.</length>
<filmtype>BW</filmtype>
<credits>
<director>Jean Cocteau</director>
<producer>Andre Paulve</producer>
<writer>Jean Cocteau</writer>
<story>Mme Leprince de Beaumont</story>
<cinematography>Henri Alekan</cinematography>
</credits>
<plot>Beauty lives in a cottage with her father and
her two wicked sisters. Once day her father comes
upon a strange mansion with an ugly sorcerer named
Beast.
</plot>
</movie>
<movie>
<title>The Bicycle Thief</title>
<genre>Social Drama</genre>
<country>Italy</country>
<language>Italian</language>
<year>1948</year>
<length>90 Min.</length>
<filmtype>BW</filmtype>
<credits>
<director>Vittorio de Sica</director>
<producer>Vittorio de Sica</producer>
<writer>Vittorio de Sica</writer>
<story>Gennarino Bartolini</story>
<cinematography>Carlo Montuori</cinematography>
</credits>
<plot>Told through the eyes of a young boy
named Bruno, <title>The Bicycle Thief</title> is the
story of his father"s struggle to provide for his family
in Rome following World War II.
</plot>
</movie>
</filmlibrary>
-
Save the file as movie1.xml. Run the file in Microsoft Internet Explorer. You should see something like this:
-
Run your text editor and type in the following:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<title>Film Library:<xsl:value-of select="filmlibrary/name"/></title>
</head>
<body>
<xsl:for-each select="filmlibrary/movie">
<h1 style="text-align: center">
<xsl:value-of select="title"/>
</h1>
<h2 style="text-align: center">
<xsl:value-of select="year"/>
<xsl:value-of select="credits/director"/>
</h2>
<p>
<xsl:value-of select="genre"/>.<xsl:value-of select="plot"/>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
-
Save the file as movie2.xsl.
-
Load the movie1.xml file into your text editor and make href point to the second version of the XSL style sheet:
<?xml-stylesheet type="text/xsl" href="movie2.xsl"?>
-
Save the file as movie2.xml. Run the file in Microsoft Internet Explorer. You should see something like this:
 |
|