<?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" encoding="iso-8859-1"/> 

<xsl:param name="smode" />
<xsl:param name="ident" />

<xsl:template match="circus">
	
	<html>
		<head>
			<title>mytable</title>
			
			<style type="text/css">
				@import url("style.css");
			</style>
		</head>
		<body>
		
			<xsl:choose>
			  <xsl:when test="not($ident)">
				<xsl:call-template name="show" />
			  </xsl:when>
			  <xsl:otherwise>
				<xsl:call-template name="artist" />
			  </xsl:otherwise>
			</xsl:choose>
		
		</body>
	</html>

</xsl:template> 


<xsl:template name="sorting">
	<xsl:choose>
	  <xsl:when test="contains($smode, 'postcode')">
		<xsl:apply-templates>
			<xsl:sort select="postcode" order="ascending" data-type="text" />
		</xsl:apply-templates>
	  </xsl:when>
	  <xsl:when test="contains($smode, 'city')">
		<xsl:apply-templates>
			<xsl:sort select="city" order="ascending" data-type="text" />
		</xsl:apply-templates> 
	  </xsl:when>
	  <xsl:otherwise>
		<xsl:apply-templates />
	  </xsl:otherwise>
	</xsl:choose>
</xsl:template> 

						
<xsl:template name="show">
	<h1>show overview</h1>

	<table>
		<thead>
			<tr>
				<th>start_day</th>
				<th>end_day</th>
				<th><a href="?smode=postcode">postcode</a></th>
				<th><a href="?smode=city">city</a></th>
				<th>address</th>
				<th>view artists</th>
			</tr>
		</thead>
		
		<tbody>
			<xsl:call-template name="sorting" />
		</tbody>
	</table>
</xsl:template>


<xsl:template name="artist">
	<h1>artists overview</h1>

	<a href="?smode={$smode}">back</a>

	<table>
		<thead>
			<tr>
				<th>name</th>
				<th>program</th>
			</tr>
		</thead>

		<tbody>
			<xsl:call-template name="sorting" />
		</tbody>
	</table>
</xsl:template>


<xsl:template match="show" name="srow">
	<xsl:choose>
	  <xsl:when test="not($ident)">
		<tr>
			<td><xsl:value-of select="current()/start_day" /></td>
			<td><xsl:value-of select="current()/end_day" /></td>
			<td><xsl:value-of select="current()/postcode" /></td>
			<td><xsl:value-of select="current()/city" /></td>
			<td><xsl:value-of select="current()/address" /></td>
			<td><a href="?ident={position()}&amp;smode={$smode}">artists</a></td>
		</tr>
	  </xsl:when>
	  <xsl:otherwise>
		<xsl:if test="position() = $ident">
			<xsl:for-each select="current()/artist">
				<xsl:call-template name="artistrow" />
			</xsl:for-each>
		</xsl:if>
	  </xsl:otherwise>
	</xsl:choose>
</xsl:template>


<xsl:template name="artistrow">
	<tr>
		<td><xsl:value-of select="current()/name" /></td>
		<td><xsl:value-of select="current()/program" /></td>
	</tr>
</xsl:template>


</xsl:stylesheet>
