<?xml version=
"1.0"
?>
<!-- Generate a list of all actors, regular, recurring and guest -->
<xsl:stylesheet
version="
1.0
"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform
"
>
<xsl:output
encoding="
ISO-8859-1
"
method="
html
"
/>
<!-- generate the main framework for the page -->
<xsl:template
match="
/series
"
>
<html
>
<head
>
<title
>
<xsl:value-of
select="
title
"
/>
, Actors
</title>
<link
href="
series.css
"
rel="
stylesheet
"
/>
</head>
<body
>
<h1
align="
center
"
>
<xsl:value-of
select="
title
"
/>
, Actors
</h1>
<hr
/>
<table
width="
100%
"
>
<tr
>
<td
align="
center
"
>
<a
href="
#regular
"
>
Regular Cast
</a>
</td>
<td
align="
center
"
>
<a
href="
#recurring
"
>
Recurring Roles
</a>
</td>
<td
align="
center
"
>
<a
href="
#guest
"
>
Guest Roles
</a>
</td>
</tr>
</table>
<xsl:apply-templates
select="
maincast
"
/>
<xsl:apply-templates
select="
recurring
"
/>
<xsl:apply-templates
select="
episodes
"
/>
</body>
</html>
</xsl:template>
<!-- all output routines call a common template "actor-row", which
takes the actor, the role and a (list of) episode(s), potentially
with links to the seasons' pages -->
<!-- output the main cast -->
<xsl:template
match="
maincast
"
>
<hr
/>
<h2
>
<a
name="
regular
"
>
Regular Cast
</a>
</h2>
<table
width="
100%
"
>
<xsl:apply-templates
mode="
regular
"
select="
member
"
/>
</table>
</xsl:template>
<!-- process a member of the regular cast -->
<xsl:template
match="
member
"
mode="
regular
"
>
<xsl:call-template
name="
actor-row
"
>
<xsl:with-param
name="
actor
"
>
<xsl:call-template
name="
linked-name
"
>
<xsl:with-param
name="
actor
"
select="
actor
"
/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param
name="
role
"
select="
role
"
/>
<xsl:with-param
name="
where
"
>
every episode
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- output the recurring roles -->
<xsl:template
match="
recurring
"
>
<hr
/>
<h2
>
<a
name="
recurring
"
>
Recurring Roles
</a>
</h2>
<table
width="
100%
"
>
<xsl:apply-templates
mode="
recurring
"
select="
member
"
>
<xsl:sort
select="
actor
"
/>
</xsl:apply-templates>
</table>
</xsl:template>
<!-- process an actor with a recurring role
we have to traverse all episodes and fetch all those the current
actor has been played on -->
<xsl:template
match="
member
"
mode="
recurring
"
>
<xsl:variable
name="
memberid
"
>
<xsl:value-of
select="
@id
"
/>
</xsl:variable>
<!-- create a block of HTML with the linked episode titles -->
<xsl:variable
name="
episodes
"
>
<xsl:for-each
select="
/series/episodes/season/episode[cast/member/@ref=$memberid]
"
>
<xsl:call-template
name="
linked-title
"
>
<xsl:with-param
name="
episode
"
select="
.
"
/>
</xsl:call-template>
<xsl:if
test="
position()!=last()
"
>
<br
/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:call-template
name="
actor-row
"
>
<!-- the actor is a target from the seasons' lists -->
<xsl:with-param
name="
actor
"
>
<xsl:call-template
name="
linked-name
"
>
<xsl:with-param
name="
actor
"
select="
actor
"
/>
<xsl:with-param
name="
id
"
select="
@id
"
/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param
name="
role
"
select="
role
"
/>
<xsl:with-param
name="
where
"
select="
$episodes
"
/>
</xsl:call-template>
</xsl:template>
<!-- make a list of all guest roles
we traverse all episodes and fetch each cast member that does have
an actor child (in terms of XML!). we could also check if the member
does not have a ref attribute -->
<xsl:template
match="
episodes
"
>
<hr
/>
<h2
>
<a
name="
guest
"
>
Guest Roles
</a>
</h2>
<table
width="
100%
"
>
<xsl:apply-templates
mode="
guest
"
select="
season/episode/cast/member[actor]
"
>
<xsl:sort
select="
actor
"
/>
</xsl:apply-templates>
</table>
</xsl:template>
<!-- process an actor with a guest role -->
<xsl:template
match="
member
"
mode="
guest
"
>
<xsl:call-template
name="
actor-row
"
>
<xsl:with-param
name="
actor
"
>
<xsl:call-template
name="
linked-name
"
>
<xsl:with-param
name="
actor
"
select="
actor
"
/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param
name="
role
"
select="
role
"
/>
<xsl:with-param
name="
where
"
>
<xsl:call-template
name="
linked-title
"
>
<xsl:with-param
name="
episode
"
select="
ancestor::episode
"
/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<!-- generate a table row for a single actor
actor and where may contain HTML code, so we have to copy their
content -->
<xsl:template
name="
actor-row
"
>
<xsl:param
name="
actor
"
/>
<xsl:param
name="
role
"
/>
<xsl:param
name="
where
"
/>
<tr
>
<td
valign="
top
"
width="
20%
"
>
<xsl:copy-of
select="
$actor
"
/>
</td>
<td
valign="
top
"
>
plays
</td>
<td
valign="
top
"
width="
20%
"
>
<xsl:value-of
select="
$role
"
/>
</td>
<td
valign="
top
"
>
on
</td>
<td
valign="
top
"
width="
50%
"
>
<xsl:copy-of
select="
$where
"
/>
</td>
</tr>
</xsl:template>
<!-- process an episode by makeing the title a link to the corresponding
episode on the appropriate season page -->
<xsl:template
name="
linked-title
"
>
<xsl:param
name="
episode
"
/>
<xsl:variable
name="
seasonid
"
>
<xsl:value-of
select="
$episode/../@id
"
/>
</xsl:variable>
<xsl:variable
name="
episodeid
"
>
<xsl:value-of
select="
$episode/@id
"
/>
</xsl:variable>
<a
href="
season{$seasonid}.html#{$episodeid}
"
>
<xsl:value-of
select="
$episode/title
"
/>
</a>
(<xsl:value-of
select="
$seasonid
"
/>
:
<xsl:value-of
select="
$episodeid
"
/>
)
</xsl:template>
<!-- translate a real name to a link into the Internet Movie Database -->
<xsl:template
name="
linked-name
"
>
<xsl:param
name="
actor
"
/>
<xsl:param
name="
id
"
/>
<a
href="
http://www.imdb.com/M/person-exact?{$actor}
"
>
<xsl:choose
>
<xsl:when
test="
$id
"
>
<xsl:attribute
name="
name
"
>
<xsl:value-of
select="
$id
"
/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:value-of
select="
$actor
"
/>
</a>
</xsl:template>
</xsl:stylesheet>