<?xml version='1.0' ?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

	<!--
	
		waters.xsl - an XSLT file to process my water collection XML data
		
		Eric Lease Morgan <eric_morgan@infomotions.com>
		http://www.infomotions.com/
		
		2006/12/03 - hard-coded home page, ick
		2006/10/01 - added Map It! function
		2005/01/01 - changed look & feel; added vspace/hspace to img
		2003/07/25 - added a / before the @ of an attribute; must be newer version of xslt?
		2002/08/02 - added img and fixed anchor only have retrieving the .xsl file from a tape backup; thank goodness for backups!
		2002/07/08 - added paragraphs to long blurbs, and may need to do this to descriptions as well
		2002/07/07 - added images and metadata
		2002/07/06 - first cut
		
	-->
	
	<!-- get the input -->
	<xsl:param name='cmd' />
	<xsl:param name='id' />
	
	<!-- make things somewhat pretty -->
	<xsl:output indent = 'yes'/>

	<!-- match the root -->
	<xsl:template match='/'>
		<html>
			<head>
				<meta>
					<xsl:attribute name='name'>creator</xsl:attribute>
					<xsl:attribute name='content'><xsl:value-of select='/water_collection/metadata/creator'/></xsl:attribute>
				</meta>
				<meta>
					<xsl:attribute name='name'>email</xsl:attribute>
					<xsl:attribute name='content'><xsl:value-of select='/water_collection/metadata/email'/></xsl:attribute>
				</meta>
				<meta>
					<xsl:attribute name='name'>URI</xsl:attribute>
					<xsl:attribute name='content'>http://infomotions.com/water/index.xml</xsl:attribute>
				</meta>
				<meta>
					<xsl:attribute name='name'>title</xsl:attribute>
					<xsl:attribute name='content'><xsl:value-of select='/water_collection/metadata/title'/></xsl:attribute>
				</meta>
				<meta>
					<xsl:attribute name='name'>date created</xsl:attribute>
					<xsl:attribute name='content'><xsl:value-of select='/water_collection/metadata/date_created'/></xsl:attribute>
				</meta>
				<meta>
					<xsl:attribute name='name'>date updated</xsl:attribute>
					<xsl:attribute name='content'><xsl:value-of select='/water_collection/metadata/date_updated'/></xsl:attribute>
				</meta>
				<meta>
					<xsl:attribute name='name'>description</xsl:attribute>
					<xsl:attribute name='content'><xsl:value-of select='/water_collection/metadata/short_blurb'/></xsl:attribute>
				</meta>
				<meta>
					<xsl:attribute name='name'>subjects</xsl:attribute>
					<xsl:attribute name='content'><xsl:value-of select='/water_collection/metadata/subjects'/></xsl:attribute>
				</meta>
				<link rel='stylesheet' type='text/css' href='/etc/style.css' media='screen'/> 
				<link rel='stylesheet' type='text/css' href='/etc/style-print.css' media='print' /> 
				<title>
					<xsl:value-of select='/water_collection/metadata/title' />
				</title>
			</head>
			<body>
				<div id='navcontainer'>
					<ul id='navlist'>
						<li><a href='/'>Home</a></li>
						<li><a href='/alex/'>Alex Catalogue</a></li>
						<li><a href='/musings/'>Musings</a></li>
						<li><a href='/gallery/'>Images</a></li>
						<li><a href='/water/index.xml' id='current'>Water</a></li>
					</ul>
				</div>
				
				<div class='menu'>
					<a href="/"><img src="/logo.gif" alt="Infomotions, Inc." width="42" height="44" border="0" /></a>
					<h1>Water Collection</h1>					
					<ul>
						<li><a href='/water/index.xml'>Introduction</a></li>
						<li><a href='/water/index.xml?cmd=getwaters'>All waters</a></li>
						<li><a href='/water/index.xml?cmd=getcollectors'>All collectors</a></li>
						<li><a href='/water/index.xml?cmd=getimages'>All images</a></li>
						<li><a href='/water/map/'>Map view</a></li>
					</ul>
				</div>

				<div class='content'>
	
					<!-- branch according to the input -->
					<xsl:choose>
						
						<xsl:when test='$cmd = ""'>
							<h1><xsl:value-of select='/water_collection/metadata/title'/></h1><xsl:value-of select='$cmd'/>
							<xsl:apply-templates select='/water_collection/metadata/long_blurb' />
						</xsl:when>
						
						<xsl:when test='$cmd = "getwaters"'>
							<h1>All waters</h1>
							<p>Here are all the waters in the collection listed alphabetically.</p>
							<ol><xsl:apply-templates select="/water_collection/waters/water/name" /></ol>
						</xsl:when>
						
						<xsl:when test='$cmd = "getimages"'>
							<h1>All images</h1>
							<p>Here are images of all the waters in the collection. Select individual images to see its details.</p>
							<xsl:apply-templates select="/water_collection/waters/water/name" />
						</xsl:when>
						
						<xsl:when test='$cmd = "getcollectors"'>
							<h1>All collectors</h1>
							<p>This is a list of all the people who have collected water. The list is ordered alphabetically by last name and then first name.</p>
							<ol><xsl:apply-templates select='/water_collection/collectors/collector' /></ol>
						</xsl:when>
						
						<xsl:when test='$cmd = "getwater"'>
							<xsl:apply-templates select="/water_collection/waters/water/name/@water_id" />
						</xsl:when>
	
						<xsl:when test='$cmd = "getcollector"'>
							<xsl:apply-templates select="/water_collection/collectors/collector/@collector_id" />
						</xsl:when>
	
						<xsl:otherwise>
							<p>Unknown value for cmd (<xsl:value-of select='$cmd' />). Call Eric.</p>
						</xsl:otherwise>
					
					</xsl:choose>
	
					<!-- footer -->
					<div class='footer'>
						<p><b>Author: </b><xsl:value-of select='/water_collection/metadata/creator' />
						<br />
						<b>Date created: </b><xsl:value-of select='/water_collection/metadata/date_created' />
						<br />
						<b>Date updated: </b><xsl:value-of select='/water_collection/metadata/date_updated' />
						<br />
						<b>URL: </b><a><xsl:attribute name='href'>http://infomotions.com/water/index.xml</xsl:attribute>http://infomotions.com/water/</a>
						</p>							
					</div>
				</div>
			</body>
		</html>
	</xsl:template>


	<!-- get all waters -->
	<xsl:template match='name'>
		
		<xsl:choose>
		
			<xsl:when test='$cmd = "" or $cmd = "getwaters"'>
				<li>
					<a><xsl:attribute name='href'>index.xml?cmd=getwater&amp;id=<xsl:value-of select='@water_id' /></xsl:attribute><xsl:value-of select='.' /></a>
				</li>
			</xsl:when>
		
			<xsl:when test='$cmd = "getimages"'>
				<a><xsl:attribute name='href'>/water/index.xml?cmd=getwater&amp;id=<xsl:value-of select='@water_id'/></xsl:attribute>
				<img>
					<xsl:attribute name='src'>./thumbnails/<xsl:value-of select='substring-before(., " ")' />-<xsl:value-of select='@water_id'/>.jpg</xsl:attribute>
					<xsl:attribute name='alt'><xsl:value-of select='../.' /></xsl:attribute>
					<xsl:attribute name='height'>160</xsl:attribute>
					<xsl:attribute name='width'>120</xsl:attribute>
					<xsl:attribute name='border'>0</xsl:attribute>
				</img>
				</a> &#160;
			</xsl:when>
		
		</xsl:choose>
		
	</xsl:template>
	
	
	<!-- long blurb -->
	<xsl:template match='long_blurb'>
		<xsl:apply-templates/>
	</xsl:template>


	<!-- paragraph -->
	<xsl:template match='p'>
		<p><xsl:apply-templates/></p>
	</xsl:template>


	<!-- hyperlink -->
	<xsl:template match='a'>
		<a><xsl:attribute name='href'><xsl:value-of select='@href'/></xsl:attribute><xsl:apply-templates /></a>
	</xsl:template>


	<!-- get all collectors -->
	<xsl:template match='collector'>
		<li>
		<a><xsl:attribute name='href'>index.xml?cmd=getcollector&amp;id=<xsl:value-of select='@collector_id' /></xsl:attribute><xsl:value-of select='./first_name' />&#160;<xsl:value-of select='./last_name' /></a>
		</li>
	</xsl:template>
	

	<!-- get individual collector -->
	<xsl:template match='@collector_id'>
		<xsl:if test='. = $id'>
			<h1>
				<xsl:value-of select='../first_name' />&#160;<xsl:value-of select='../last_name' />
			</h1>
			<table>
				<tr>
					<td align='right'>
						<b>Collector</b> 
					</td>
					<td>
						<xsl:value-of select='../first_name' />&#160;<xsl:value-of select='../last_name' />
					</td>
				</tr>
				<tr valign='top'>
					<td align='right'>
						<b>Water(s)</b> 
					</td>
					<td>
						<xsl:for-each select='../waters/name'>
							<a><xsl:attribute name='href'>index.xml?cmd=getwater&amp;id=<xsl:value-of select='@water_id'/></xsl:attribute><xsl:value-of select='.'/></a><br/>
						</xsl:for-each>
					</td>
				</tr>
			</table>
		</xsl:if>
	</xsl:template>

	<!-- get individual water -->
	<xsl:template match="@water_id">
		<xsl:if test='. = $id'>
			<h1>
				<xsl:value-of select='../.' />
			</h1>
			<table>
			<tr valign='top'>
			<td align='center'>
				<a><xsl:attribute name='href'>./originals/<xsl:value-of select='substring-before(../., " ")' />-<xsl:value-of select='.'/>.jpg</xsl:attribute>
				<img>
					<xsl:attribute name='src'>./thumbnails/<xsl:value-of select='substring-before(../., " ")' />-<xsl:value-of select='.'/>.jpg</xsl:attribute>
					<xsl:attribute name='alt'><xsl:value-of select='../.' /></xsl:attribute>
					<xsl:attribute name='height'>160</xsl:attribute>
					<xsl:attribute name='width'>120</xsl:attribute>
					<xsl:attribute name='border'>0</xsl:attribute>
				</img>
				</a>
				<br />
				<small>
					<a><xsl:attribute name='href'>./originals/<xsl:value-of select='substring-before(../., " ")' />-<xsl:value-of select='.'/>.jpg</xsl:attribute>Full image</a>
				</small>
			</td>
			<td>
				<table>
					<tr valign='top'>
						<td align='right'>
							<b>Name</b> 
						</td>
						<td>
							<xsl:value-of select='../.' />
						</td>
					</tr>
					<tr valign='top'>
						<td align='right'>
							<b>Date</b> 
						</td>
						<td>
							<xsl:value-of select='../../date_collected/month' />/<xsl:value-of select='../../date_collected/day' />/<xsl:value-of select='../../date_collected/year' />
						</td>
					</tr>
					<tr valign='top'>
						<td align='right'>
							<b>Collector(s)</b> 
						</td>
						<td>
							<xsl:for-each select='../../collectors/collector'>
								<a><xsl:attribute name='href'>index.xml?cmd=getcollector&amp;id=<xsl:value-of select='@collector_id'/></xsl:attribute><xsl:value-of select='first_name'/>&#160;<xsl:value-of select='last_name'/></a><br/>
							</xsl:for-each>
						</td>
					</tr>
					<tr valign='top'>
						<td align='right'>
							<b>Description</b> 
						</td>
						<td>
							<xsl:apply-templates select='../../description'/>
						</td>
					</tr>
					<tr valign='top'>
						<td align='right'>
							<b>Location</b> 
						</td>
						<td>
							<a><xsl:attribute name='href'>./map/?lat=<xsl:value-of select='.././@lat'/>&amp;lng=<xsl:value-of select='.././@lng'/></xsl:attribute><xsl:value-of select='.././@lat'/>&#186;N <xsl:value-of select='.././@lng'/>&#186;W </a>
						</td>
					</tr>
				</table>
			</td>
			</tr>
			</table>
		</xsl:if>
	</xsl:template>


	<!-- descriptions -->
	<xsl:template match='description'>
		<xsl:apply-templates/>
	</xsl:template>

	<!-- image -->
	<xsl:template match='img'>
		<img>
			<xsl:attribute name='src'><xsl:value-of select='@src'/></xsl:attribute>
			<xsl:attribute name='align'><xsl:value-of select='@align'/></xsl:attribute>
			<xsl:attribute name='vspace'><xsl:value-of select='@vspace'/></xsl:attribute>
			<xsl:attribute name='hspace'><xsl:value-of select='@hspace'/></xsl:attribute>
			<xsl:attribute name='border'><xsl:value-of select='@border'/></xsl:attribute>
		</img>
	</xsl:template>

</xsl:stylesheet>
