<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output 
	method ="html"
	doctype-public = "-//W3C//DTD HTML 4.01 Transitional//EN" 
	encoding="ISO-8859-1" />


<xsl:variable name="plus">+</xsl:variable>

<xsl:template match="/">
	
	<html>
		<head>
			<meta http-equiv="Pragma" content="no-cache" />
			<meta http-equiv="Expires" content="-1" /> 
			  <title>Nuke History - annotated</title>
			  <link rel="stylesheet" type="text/css" href="styles/history.css"></link>
		</head>
		<body>
			<h1>Nuke History</h1>
			<h3>X-rays to H-bombs</h3>
			<div id="nukesorg"><a href="index.html">outline version</a> || <a href="http://nukes.org/">nukes.org</a></div>
			<div id="base">
			   <xsl:apply-templates select="document('history.xml')/root"/>
			</div>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="root">
		<xsl:for-each select="when">
			<div class="year">
				<b class="yearHead"><xsl:value-of select="@year"/></b>
				<xsl:apply-templates select="*"/>
		  </div>
		</xsl:for-each> 
	</xsl:template>
	
	<xsl:template match="item">
		<div class="item">	
			<xsl:apply-templates select="*"/>
			
			<div class="searches"><b>SEARCH: </b> 
				
			<xsl:call-template name="searches">
				<xsl:with-param name="text" select="." />
				<xsl:with-param name="year" select="parent::when/@year" />
			</xsl:call-template>
			
			&gt;&gt;&gt; <b>TERMS:</b> <xsl:text> </xsl:text>
			 <xsl:for-each select="who/person">&#8220;<xsl:value-of select="@first" /><xsl:text> </xsl:text>  <xsl:value-of select="@last" />&#8221; </xsl:for-each><xsl:for-each select="what/thing"> &#8220;<xsl:value-of select="@name"/>&#8221; </xsl:for-each>
			
			</div>
		</div>
	</xsl:template>
	

	<xsl:template match="what">
		<p>
			<b class="header">WHAT:<br/> </b>
			<xsl:for-each select="thing">
			<b>
			<a class="thingLink">
				<xsl:attribute name="href">http://www.google.com/search?q=%22<xsl:value-of select="@name"/>%22</xsl:attribute>
				<xsl:attribute name="title">Search google for: "<xsl:value-of select="@name"/>"</xsl:attribute>
					<xsl:value-of select="@name"/></a><br/></b>
				<xsl:for-each select="note">
					* <xsl:value-of select="." /><br/>
				</xsl:for-each>		
			</xsl:for-each>	
			<xsl:for-each select="note">
				* <xsl:value-of select="." /><br/>
		  </xsl:for-each>	
	  </p>		
	</xsl:template>

	<xsl:template match="who">
		<p>
		<b class="header">WHO: <br/></b>
		<xsl:for-each select="person">
			<b>
			<a class="whoLink">
				<xsl:attribute name="href">http://www.google.com/search?q=%22<xsl:value-of select="@first"/>+<xsl:value-of select="@last"/>%22</xsl:attribute>
				<xsl:attribute name="title">Search google for: "<xsl:value-of select="@first"/><xsl:text> </xsl:text><xsl:value-of select="@last"/>"</xsl:attribute>
	
				<xsl:value-of select="@first"/> <xsl:text> </xsl:text>
				<xsl:value-of select="@last"/></a><br/></b>
			<xsl:for-each select="note">
				* <xsl:value-of select="." /><br/>
			</xsl:for-each>		
			
		</xsl:for-each>
			<xsl:for-each select="note">
				* <xsl:value-of select="." /><br/>
			</xsl:for-each>		
	  </p>		
	</xsl:template>

	<xsl:template match="how">
		<p>
		<b class="header">HOW: <br/></b>
		<xsl:for-each select="method">
				* <xsl:apply-templates select="."/>
			<br/>
		</xsl:for-each>
	  </p>		
	</xsl:template>

	<xsl:template match="notes">
		<p>
		<b class="header">NOTES: <br/></b>
		<xsl:for-each select="note">
				* <xsl:apply-templates select="."/>
			<br/>
		</xsl:for-each>
	  </p>		
	</xsl:template>

	<xsl:template match="pubs">
		<p>
		<b class="header">In their own words: <br/></b>
		<!--Online Source Texts: -->
		<xsl:for-each select="pub">
			* <b><a>
			<xsl:attribute name="href"><xsl:value-of select="@href" /></xsl:attribute>
			<xsl:attribute name="title">GO TO: <xsl:value-of select="@href" /></xsl:attribute>
				<xsl:value-of select="title" />
			</a></b>
				
			by <xsl:value-of select="author" />;
			<b>source: </b> <xsl:value-of select="source" />
			<br/>
		</xsl:for-each>
	  </p>		
	</xsl:template>

	<xsl:template name="searches">
		<xsl:param name="text" />
		<xsl:param name="year" />
		<xsl:variable name="sstring"><xsl:for-each select="$text/who/person">%22<xsl:value-of select="@first" />+<xsl:value-of select="@last" />%22+</xsl:for-each><xsl:for-each select="$text/what/thing">%22<xsl:call-template name="replace-spaces"><xsl:with-param name="str" select="@name"/></xsl:call-template>%22</xsl:for-each></xsl:variable>
		
<a>
<xsl:attribute name="href">http://www.google.com/search?q=<xsl:value-of select="$sstring"/></xsl:attribute>google
</a>
.			<a>
<xsl:attribute name="href">http://images.google.com/images?q=<xsl:value-of select="$sstring"/></xsl:attribute>google images
</a>
||			<a>
<xsl:attribute name="href">http://en.wikipedia.org/w/index.php?search=<xsl:value-of select="$sstring"/></xsl:attribute>wikipedia
</a>
||			<a>
<xsl:attribute name="href">http://search.yahoo.com/search?p=<xsl:value-of select="$sstring"/></xsl:attribute>yahoo
</a>
.			<a>
<xsl:attribute name="href">http://images.search.yahoo.com/search/images?p=<xsl:value-of select="$sstring"/></xsl:attribute>yahoo images
</a>			
	</xsl:template>	

	<xsl:template name="replace-spaces">
		<xsl:param name="str" />
		<xsl:choose>
	  		<xsl:when test="contains($str, ' ')">
				<xsl:value-of select="substring-before($str,' ')"  disable-output-escaping="yes" />
				<xsl:value-of select="$plus" disable-output-escaping="yes" />
				<xsl:call-template name="replace-spaces">
					<xsl:with-param name="str" select="substring-after($str,' ')" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$str" disable-output-escaping="yes"  />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>	

	<xsl:template match="tool">
		<a class="toolLink">
			<xsl:attribute name="href">http://www.google.com/search?q=%22<xsl:call-template name="replace-spaces"><xsl:with-param name="str" select="."/></xsl:call-template>%22+radiation</xsl:attribute>
			<xsl:attribute name="title">Search google for: <xsl:value-of select="."/> + radiation</xsl:attribute>
			<xsl:value-of select="." />
		</a>
	</xsl:template>
	
	<xsl:template match="i">
		<i><xsl:value-of select="." /></i>
	</xsl:template>



<!-- IDENTITY TRANSFORM -->	
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>

	
</xsl:stylesheet>