<?xml version="1.0" encoding="ISO-8859-1" ?>
	<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" />
	<xsl:variable name="title" select="/document/metadata/title" />
	<xsl:key name="eventDate" match="/document/results/result" use="@date" />
	<xsl:key name="stateName" match="/document/results/result" use="@statefull" />
	<xsl:key name="marketArea" match="/document/results/result" use="@marketareaid" />
	<xsl:template match="/">
		<html>
			<head>
				<title>
					<xsl:value-of select="$title" />
				</title>
				<link rel="stylesheet" href="http://www.ticketwarehouse.us/stylesheet.css" type="text/css" /> 
			</head>
			<body>
				<div id="titlebox">
					<div id="sitetitleimg">
						<a href="http://www.ticketwarehouse.us/"><img src="//www.ticketwarehouse.us/img/ticketwarehouse.gif" alt="Ticket Warehouse Home Page" /></a>
					</div>
					<div id="callus">
						To order by phone: 1-888-252-8499
					</div>
					<div id="sitelinks">
						Local Event and Ticket Finder
					</div>
				</div>
				<div id="side">
					<h1>Site Links</h1>
					<p>
						<b>Find by Location</b><br />
						<a href="/" class="indent">By State</a><br />
						<a href="/regions.xml" class="indent">By Metro Area</a><br />
						<b>Find by Type</b><br />
						<a href="/sports/" class="indent">Sporting Events</a><br />
						<a href="/concert/" class="indent">Concerts and Music</a><br />
						<a href="/theater/" class="indent">Theater Productions</a>
					</p>
					<h1>About the system</h1>
					<p>TicketWarehouse.us is a service of Ticket Warehouse, providing users with listings of local events and ticket information.</p>
					<xsl:apply-templates select="document/updates" />
					<xsl:apply-templates select="document/statistics" />
					<xsl:apply-templates select="document/params" />
				</div>
				<div id="main">
					<xsl:apply-templates select="document/content" />
					<xsl:apply-templates select="document/results" />
					<div id="copyright">
						Ticket Warehouse is not affiliated with any sports team, performer, ticket agency, venue, promoter or box office. Event and venue names are used on this site for descriptive purposes only. Prices listed on this site may be above face value. Dates and times subject to change.
					</div>
				</div>
			</body>
		</html>
	</xsl:template>
	
	<xsl:template match="/document/updates">
		<h1>Latest Updates</h1>
		<xsl:for-each select="update">
			<p><b><xsl:value-of select="@date" /></b> - <xsl:value-of select="." /></p>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="/document/statistics">
		<h1>System Statistics</h1>
		<p>
			<xsl:for-each select="stat">
				<xsl:value-of select="@name" />: <xsl:value-of select="@value" />
				<xsl:if test="position()!=last()">
					<br />
				</xsl:if>
			</xsl:for-each>
		</p>
	</xsl:template>
	
	<xsl:template match="/document/params">
		<h1>Query Parameters</h1>
		<p>The following information was included in your request, and is shown here for troubleshooting purposes.</p>
		<p>
			<xsl:for-each select="param">
				<xsl:value-of select="@name" />: <xsl:value-of select="@value" />
				<xsl:if test="position()!=last()">
					<br />
				</xsl:if>
			</xsl:for-each>
		</p>
	</xsl:template>
	
	<xsl:template match="/document/content/pagename">
		<h1><xsl:value-of select="." /></h1>
	</xsl:template>
	<xsl:template match="/document/content/header">
		<h2><xsl:value-of select="." /></h2>
	</xsl:template>
	<xsl:template match="/document/content/p">
		<p><xsl:apply-templates /></p>
	</xsl:template>
	<xsl:template match="/document/content/p/a">
		<a href="{@href}"><xsl:value-of select="." /></a>
	</xsl:template>
	
	<xsl:template match="/document/results">
		<h3><xsl:value-of select="@title" /></h3>
		<p><xsl:value-of select="details" /></p>
		<xsl:choose>
			<xsl:when test="contains(@type, 'selection')">
				<ul>
					<xsl:for-each select="result">
						<li><a href="{@url}"><xsl:value-of select="@name" /></a></li>
					</xsl:for-each>
				</ul>
			</xsl:when>
			<xsl:when test="contains(@type, 'states')">
				<xsl:for-each select="result[count(. | key('marketArea', @marketareaid)[1]) = 1]">
					<xsl:sort select="@marketareaname" />
					<h2><xsl:value-of select="@marketareaname" /> Area</h2>
					<p class="location"><a href="{@maurl}">Click here to view the schedule for this area.</a></p>
					<ul>
						<xsl:for-each select="key('marketArea', @marketareaid)">
							<xsl:sort select="@name" />
							<li><a href='{@url}'><xsl:value-of select="@name" /></a> - <span class="location">(<xsl:value-of select="@city" />)</span></li>
						</xsl:for-each>
					</ul>
				</xsl:for-each>
			</xsl:when>
			<xsl:when test="contains(@type, 'areas')">
				<p>We currently have <xsl:value-of select="count(result)" /> metropolitan areas in our database. These areas are presented sorted by state.</p>
				<xsl:for-each select="result[count(. | key('stateName', @statefull)[1]) = 1]">
					<xsl:sort select="@statefull" />
					<xsl:if test="@state!='AB' and @state!='ON' and @state!='PR'">
						<h2><xsl:value-of select="@statefull" /></h2>
						<ul>
							<xsl:for-each select="key('stateName', @statefull)">
								<xsl:sort select="@name" />
								<li><a href="{@url}"><xsl:value-of select="@name" /></a></li>
							</xsl:for-each>
						</ul>
					</xsl:if>
				</xsl:for-each>
			</xsl:when>
			<xsl:when test="contains(@type, 'calendar')">
				<xsl:choose>
					<xsl:when test="count(result) &gt; 0">
						<div class="center">
							<table class="listing">
								<xsl:for-each select="result[count(. | key('eventDate', @date)[1]) = 1]">
									<tr class="headerline"><td colspan="4"><xsl:value-of select="@date" /></td></tr>
									<xsl:for-each select="key('eventDate', @date)">
										<xsl:sort select="@time" />
										<tr class="eventline">
											<td>
												<xsl:choose>
													<xsl:when test="@visitorname">
														<xsl:choose>
															<xsl:when test="@type = 'concert'">
																<a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a> with <a href="{@visitorurl}" class="event"><xsl:value-of select="@visitorname" /></a>
															</xsl:when>
															<xsl:when test="@type = 'sports'">
																<a href="{@visitorurl}" class="event"><xsl:value-of select="@visitorname" /></a> at <a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a>
															</xsl:when>
															<xsl:otherwise>
																<a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a> and <a href="{@visitorurl}" class="event"><xsl:value-of select="@visitorname" /></a>
															</xsl:otherwise>
														</xsl:choose>
													</xsl:when>
													<xsl:otherwise>
														<a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a>
													</xsl:otherwise>
												</xsl:choose>
											</td>
											<td>
												<a href="{@venueurl}" class="event"><xsl:value-of select="@venuename" /></a>
												<span class="location"> (<xsl:value-of select="@venuelocation" />) </span>
											</td>
											<td>
												<span style="white-space: nowrap;"><xsl:value-of select="@time" /></span>
											</td>
											<td><a href="{@ticketurl}">View Tickets</a></td>
										</tr>
									</xsl:for-each>
								</xsl:for-each>
							</table>
						</div>
					</xsl:when>
					<xsl:otherwise>
						<p>There are no events of the requested type or in the requested timeframe.</p>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="contains(@type, 'schedule')">
				<xsl:choose>
					<xsl:when test="count(result) &gt; 0">
						<div class="center">
							<table class="listing">
								<xsl:for-each select="result">
									<tr class="eventline">
										<td>
											<xsl:choose>
												<xsl:when test="@visitorname">
													<xsl:choose>
														<xsl:when test="@type = 'concert'">
															<a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a> with <a href="{@visitorurl}" class="event"><xsl:value-of select="@visitorname" /></a>
														</xsl:when>
														<xsl:when test="@type = 'sports'">
															<a href="{@visitorurl}" class="event"><xsl:value-of select="@visitorname" /></a> at <a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a>
														</xsl:when>
														<xsl:otherwise>
															<a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a> and <a href="{@visitorurl}" class="event"><xsl:value-of select="@visitorname" /></a>
														</xsl:otherwise>
													</xsl:choose>
												</xsl:when>
												<xsl:otherwise>
													<a href="{@homeurl}" class="event"><xsl:value-of select="@homename" /></a>
												</xsl:otherwise>
											</xsl:choose>
										</td>
										<td><xsl:value-of select="@date" /> at <xsl:value-of select="@time" /></td>
										<td><a href="{@ticketurl}">View Tickets</a></td>
									</tr>
								</xsl:for-each>
							</table>
						</div>
					</xsl:when>
					<xsl:otherwise>
						<p>There are no events currently listed in this area.</p>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<p>The result type is not recognized.</p>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>