<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output
	method="xml"
	omit-xml-declaration="yes"
	media-type="text/html"
	encoding="ISO-8859-1"
	indent="yes"	
	doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
	doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

<xsl:include href="library.xsl"/>

<!-- parameters -->

<xsl:param name="version">web</xsl:param>
<xsl:param name="theme">medium</xsl:param>
<xsl:param name="copyYear">2005</xsl:param>
<xsl:param name="error"/>
<xsl:param name="messageTitle"/>
<xsl:param name="queryString"/>
<xsl:param name="randomPhotoIndex"/>
<xsl:param name="randomPhotoTitle"/>

<xsl:template match="page">
<html lang="en">
	<head>
		<title>
			<xsl:value-of select="$domain"/>
			<xsl:value-of select="$separator"/>	
			<xsl:call-template name="title-generator">
				<xsl:with-param name="markup" select="false()"/>
			</xsl:call-template>
		</title>
		
		<!-- meta tags -->
		<meta name="author" content="Scott Martin"/>
		<meta name="description" content="coffeeblack.org: award-winning software engineering, web and database development since 1999."/>
		<meta name="keywords" content="Scott Martin, coffeeblack, coffee, black, software, web, development, engineering, portfolio"/>
		<meta name="robots" content="index,follow"/>
		<meta name="MSSmartTagsPreventParsing" content="TRUE"/>

		<!-- site icon -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="rel">shortcut icon</xsl:with-param>
			<xsl:with-param name="type">null</xsl:with-param>
			<xsl:with-param name="target">
				<xsl:text>http://www.</xsl:text>
				<xsl:value-of select="$site"/>
				<xsl:text>/favicon.ico</xsl:text>
			</xsl:with-param>
		</xsl:call-template>

		<!-- generate base style sheet -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="rel">stylesheet</xsl:with-param>
			<xsl:with-param name="type">text/css</xsl:with-param>
			<xsl:with-param name="media">all</xsl:with-param>
			<xsl:with-param name="target">/styles/common.css</xsl:with-param>
		</xsl:call-template>
		
		<!-- print version present with web version, for printing -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="rel">stylesheet</xsl:with-param>
			<xsl:with-param name="type">text/css</xsl:with-param>
			<xsl:with-param name="target">/styles/print.css</xsl:with-param>
			<xsl:with-param name="media">print</xsl:with-param>
		</xsl:call-template>
				
		<xsl:call-template name="print-version-generator">
			<xsl:with-param name="mode">head</xsl:with-param>
		</xsl:call-template>

		<xsl:call-template name="theme-generator"/>
		
		<!-- chapters -->
		<xsl:call-template name="navigation-generator">
			<xsl:with-param name="mode">chapters</xsl:with-param>
		</xsl:call-template>

		<!-- top -->
		<xsl:if test="not(@section='home')">
			<xsl:call-template name="link-generator">
				<xsl:with-param name="title">
					<xsl:value-of select="$domain"/>
					<xsl:text> Home</xsl:text>
				</xsl:with-param>
				<xsl:with-param name="rel">top</xsl:with-param>
				<xsl:with-param name="target">/</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="link-generator">
				<xsl:with-param name="title">Up one level</xsl:with-param>
				<xsl:with-param name="rel">up</xsl:with-param>
				<xsl:with-param name="target">../</xsl:with-param>
			</xsl:call-template>
		</xsl:if>
		
		<!-- feeds -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="title">coffeeblack RSS feed</xsl:with-param>
			<xsl:with-param name="rel">alternate</xsl:with-param>
			<xsl:with-param name="type">application/rss+xml</xsl:with-param>
			<xsl:with-param name="target">/feeds/rss/</xsl:with-param>
		</xsl:call-template>

		<!-- search -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="title">
				<xsl:text>Search </xsl:text>
				<xsl:value-of select="$site"/>
				<xsl:text> using Google</xsl:text>
			</xsl:with-param>
			<xsl:with-param name="rel">search</xsl:with-param>
			<xsl:with-param name="target">#search</xsl:with-param>
		</xsl:call-template>

		<!-- index -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="title">Site Sections</xsl:with-param>
			<xsl:with-param name="rel">index</xsl:with-param>
			<xsl:with-param name="target">/about/#sections</xsl:with-param>
		</xsl:call-template>
		
		<!-- author -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="title">Author</xsl:with-param>
			<xsl:with-param name="rel">author</xsl:with-param>
			<xsl:with-param name="target">/about/#author</xsl:with-param>
		</xsl:call-template>

		<!-- copyright -->
		<xsl:call-template name="link-generator">
			<xsl:with-param name="title">Copyright Information</xsl:with-param>
			<xsl:with-param name="rel">copyright</xsl:with-param>
			<xsl:with-param name="target">/about/#copyright</xsl:with-param>
		</xsl:call-template>
		
		<!-- other versions, subsections, etc. -->
		<xsl:apply-templates select="content|related" mode="head"/>	

		<!-- scripts -->
		<xsl:call-template name="script-generator">
			<xsl:with-param name="src">/scripts/styleswitcher.js</xsl:with-param>
		</xsl:call-template>
		<xsl:call-template name="script-generator">
			<xsl:with-param name="src">/scripts/global.js</xsl:with-param>
		</xsl:call-template>
		
	</head>
	<body>

		<xsl:if test="not($messageTitle='')">
			<xsl:attribute name="id">messageBody</xsl:attribute>
		</xsl:if>

		<div id="container">
			<h1>
				<span>
					<xsl:value-of select="$domain"/>
				</span>
			</h1>

			<ul id="navigation">
				<xsl:call-template name="navigation-generator">
					<xsl:with-param name="section-list" select="$site-sections"/>
				</xsl:call-template>
			</ul>

			<div id="content">
				<div id="textContainer">
					<div id="text">
						<h2>
							<xsl:call-template name="title-generator"/>
						</h2>

						<xsl:apply-templates select="content/random-image" mode="header"/>

						<xsl:if test="not($error='')">
							<p class="error">
								<xsl:value-of select="$error"/>
							</p>
						</xsl:if>

						<xsl:apply-templates select="content"/>

						<dl class="mention" id="notice">
							<dt>
								<a>
									<xsl:attribute name="href">
										<xsl:call-template name="target-handler">
											<xsl:with-param name="target">/about/#copyright</xsl:with-param>
										</xsl:call-template>
									</xsl:attribute>
									<xsl:text>Copyright</xsl:text>
								</a>
								<xsl:text> </xsl:text>
							</dt>
							<dd>
								<xsl:call-template name="entity-handler">
									<xsl:with-param name="name">copy</xsl:with-param>
								</xsl:call-template>
								<xsl:text> </xsl:text>
								<xsl:text>2001-</xsl:text>
								<xsl:value-of select="$copyYear"/>
								<xsl:text> </xsl:text>
							</dd>
							<dd>								
								<a>
									<xsl:attribute name="href">
										<xsl:call-template name="target-handler">
											<xsl:with-param name="target">/about/#author</xsl:with-param>
										</xsl:call-template>
									</xsl:attribute>
									<xsl:text>Scott Martin</xsl:text>
								</a>
								<xsl:text>. </xsl:text>
							</dd>
							<dd>All Rights Reserved. </dd>
							<dt>Valid </dt>
							<dd>
								<a href="http://validator.w3.org/check/referer">
									<acronym title="Extensible Hyptertext Markup Language">XHTML</acronym>
								</a>
								<xsl:text> and </xsl:text>
							</dd>
							<dd>
								<a href="javascript://" onclick="validateStyle();">
									<acronym title="Cascading Style Sheets">CSS</acronym>
								</a>
								<xsl:text>.</xsl:text>
							</dd>
						</dl>						
					</div>
				</div>

				<div id="sidebar">
					<xsl:apply-templates select="related"/>

					<xsl:if test="related/appendix|related/bookmark">
						<h5>Related Links</h5>
						<ul class="links">
							<xsl:apply-templates select="related/appendix|related/bookmark" mode="sidebar"/>
						</ul>
					</xsl:if>

					<h5>Other Versions Of This Page</h5>
					<ul class="links">
						<xsl:apply-templates select="related/alternate" mode="sidebar">
							<xsl:sort select="@title"/>
						</xsl:apply-templates>
						<xsl:call-template name="print-version-generator"/>
					</ul>

					<h5>Themes</h5>
					<ul class="links" id="themes">
						<xsl:call-template name="theme-generator">
							<xsl:with-param name="mode">sidebar</xsl:with-param>
						</xsl:call-template>						
					</ul>

					<h5><a name="search">Search</a></h5>
					<p>Enter some text to search for:</p>
					<form method="post">
						<xsl:attribute name="action">
							<xsl:call-template name="target-handler">
								<xsl:with-param name="target">/search/</xsl:with-param>
							</xsl:call-template>
						</xsl:attribute>
						<div>
							<input id="searchTerm" name="term" type="text" class="text"/>
							<input id="searchButton" class="button" type="submit" value="Go" title="Search {$site} using Google"/>					
						</div>	
					</form>
				</div>
			</div>

		</div>
	</body>
</html>
</xsl:template>

<!-- related -->

<!-- to be overridden -->
<xsl:template match="content|related">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="content|related" mode="head">
	<xsl:apply-templates select="descendant::resources" mode="head"/>

	<xsl:apply-templates select="alternate[@type='text/css']">
		<xsl:sort select="@title"/>
	</xsl:apply-templates>

	<xsl:apply-templates select="alternate[not(@type='text/css')]|index|contents|first|prev|next|last|up|bookmark|version|chapter|section|subsection|appendix|resources" mode="head"/>
</xsl:template>

<xsl:template match="related/section">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="related/section/title">
	<h5>
		<xsl:apply-templates/>
	</h5>
</xsl:template>

<!-- suppress normal execution -->
<xsl:template match="alternate|index|contents|first|prev|next|last|up|bookmark|version|chapter|section|subsection|appendix"/>

<!-- for generating link elements in document head -->
<xsl:template
	match="alternate|index|contents|first|prev|next|last|up|bookmark|version|chapter|section|subsection|appendix"
	mode="head">

	<xsl:if test="@target">
		<xsl:call-template name="link-generator"/>
	</xsl:if>
</xsl:template>

<xsl:template match="alternate[@type='text/css']" mode="sidebar">
	<li>
		<a href="javascript://" onclick="setActiveStyleSheet('{@title}');">
			<xsl:value-of select="@title"/>
		</a>	
	</li>
</xsl:template>

<xsl:template name="print-version-generator">
<xsl:param name="mode"/>

	<xsl:choose>
		<xsl:when test="$mode='head'">
			<xsl:call-template name="link-generator">
				<xsl:with-param name="title">Printer-friendly</xsl:with-param>
				<xsl:with-param name="rel">alternate</xsl:with-param>
				<xsl:with-param name="type">text/css</xsl:with-param>
				<xsl:with-param name="target">/styles/print.css</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<li>
				<a href="javascript://" onclick="setActiveStyleSheet('Printer-friendly');">Printer-friendly</a>
			</li>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="/page[not(@messageType='error')]/related/alternate[not(@type='text/css')]" mode="sidebar">
	<li>
		<a>
			<xsl:attribute name="href">
				<xsl:call-template name="target-handler">
					<xsl:with-param name="target" select="@target"/>
				</xsl:call-template>
			</xsl:attribute>
			<xsl:if test="@type">
				<xsl:attribute name="type">
					<xsl:value-of select="@type"/>
				</xsl:attribute>
			</xsl:if>
			
			<xsl:choose>
				<xsl:when test="@description">
					<acronym title="{@description}">
						<xsl:value-of select="@title"/>		
					</acronym>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@title"/>
				</xsl:otherwise>
			</xsl:choose>
			
		</a>
	</li>
</xsl:template>

<xsl:template match="bookmark|appendix" mode="sidebar">
	<li>
		<a>
			<xsl:attribute name="href">
				<xsl:call-template name="target-handler">
					<xsl:with-param name="target">
						<xsl:value-of select="@target"/>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:attribute>
			<xsl:if test="@type">
				<xsl:attribute name="type">
					<xsl:value-of select="@type"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:value-of select="@title"/>
		</a>
	</li>
</xsl:template>

<xsl:template match="content//section">
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match="content/section/title">
	<h3>
		<xsl:apply-templates/>
	</h3>
</xsl:template>

<xsl:template match="content/section/section/title">
	<h4>
		<xsl:apply-templates/>
	</h4>
</xsl:template>

<xsl:template match="content//anchor">
	<a class="anchor">
		<xsl:attribute name="name">
			<xsl:value-of select="@name"/>
		</xsl:attribute>
		<xsl:apply-templates/>
	</a>	
</xsl:template>

<xsl:template match="resources[bookmark or appendix]" mode="head">
	<xsl:apply-templates select="bookmark|appendix" mode="head"/>
</xsl:template>

<xsl:template match="resources[bookmark or appendix]">
	<h4>
		<xsl:value-of select="@title"/>
	</h4>
	<ul class="links">
		<xsl:apply-templates select="bookmark|appendix"/>
	</ul>
</xsl:template>

<xsl:template match="resources/bookmark|resources/appendix">
	<li>
		<a>
			<xsl:attribute name="href">
				<xsl:call-template name="target-handler">
					<xsl:with-param name="target" select="@target"/>
				</xsl:call-template>
			</xsl:attribute>

			<xsl:value-of select="@title"/>
		</a>
	</li>
</xsl:template>

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

<!-- links -->

<xsl:template match="link">
	<a>
		<xsl:attribute name="href">
			<xsl:call-template name="target-handler">
				<xsl:with-param name="target" select="@target"/>
			</xsl:call-template>
		</xsl:attribute>
		<xsl:if test="starts-with(@target, 'http://')">
			<xsl:attribute name="class">external</xsl:attribute>
		</xsl:if>
		<xsl:if test="@onclick">
			<xsl:attribute name="onclick">
				<xsl:value-of select="@onclick"/>
			</xsl:attribute>
		</xsl:if>
		<xsl:if test="@title">
			<xsl:attribute name="title">
				<xsl:value-of select="@title"/>
			</xsl:attribute>
		</xsl:if>
		<xsl:if test="@type">
			<xsl:attribute name="type">
				<xsl:value-of select="@type"/>
			</xsl:attribute>
		</xsl:if>
		<xsl:apply-templates/>
	</a>
</xsl:template>

<!-- lists -->

<xsl:template match="list">
	<xsl:choose>
		<xsl:when test="@type='ordered'">
			<ol>
				<xsl:apply-templates/>
			</ol>
		</xsl:when>
		<xsl:when test="@type='definition'">
			<dl>
				<xsl:apply-templates/>
			</dl>
		</xsl:when>
		<xsl:otherwise>
			<ul>
				<xsl:attribute name="class">
					<xsl:choose>
						<xsl:when test="ancestor::related">links</xsl:when>
						<xsl:otherwise>items</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>

				<xsl:apply-templates/>
			</ul>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="list/item">
	<li>
		<xsl:apply-templates/>
	</li>
</xsl:template>

<xsl:template match="list[@type='definition']/title">
	<dt>
		<xsl:apply-templates/>
	</dt>
</xsl:template>

<xsl:template match="list[@type='definition']/definition">
	<dd>
		<xsl:apply-templates/>
	</dd>
</xsl:template>

<xsl:template match="details">
	<dl>		
		<xsl:apply-templates/>
	</dl>
</xsl:template>

<xsl:template match="details/title">
	<dt>
		<xsl:apply-templates/>
	</dt>
</xsl:template>

<xsl:template match="details/description">
	<dd>
		<xsl:apply-templates/>
	</dd>
</xsl:template>

<!-- images -->

<xsl:template match="random-image"/>

<xsl:template match="random-image" mode="header">
	<xsl:if test="$randomPhotoIndex and not($randomPhotoIndex='')">
		<xsl:call-template name="image-generator">
			<xsl:with-param name="type">preview thumb</xsl:with-param>
			<xsl:with-param name="number" select="$randomPhotoIndex"/>
			<xsl:with-param name="text">
				<xsl:text>Larger version of </xsl:text>
				<xsl:value-of select="$randomPhotoTitle"/>
			</xsl:with-param>
			<xsl:with-param name="caption" select="$randomPhotoTitle"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

<xsl:template match="image">
	<xsl:call-template name="image-generator">
		<xsl:with-param name="type" select="@type"/>
	</xsl:call-template>
</xsl:template>

<xsl:template match="image/caption">
	<dd>
		<xsl:apply-templates/>
	</dd>
</xsl:template>

<xsl:template match="quote">
	<xsl:call-template name="entity-handler">
		<xsl:with-param name="name">ldquo</xsl:with-param>
	</xsl:call-template>
	<xsl:apply-templates/>
	<xsl:call-template name="entity-handler">
		<xsl:with-param name="name">rdquo</xsl:with-param>
	</xsl:call-template>
</xsl:template>

<xsl:template match="entity" name="entity-handler">
<xsl:param name="name" select="@name"/>

	<xsl:text disable-output-escaping="yes">&amp;</xsl:text>
	<xsl:if test="@type='number'">#</xsl:if>
	<xsl:value-of select="$name"/>
	<xsl:text>;</xsl:text>
</xsl:template>

<xsl:template match="blockquote">
	<blockquote>
		<xsl:apply-templates/>
	</blockquote>
</xsl:template>

<xsl:template match="emphasis|callout|code">
	<span class="{name()}">
		<xsl:apply-templates/>
	</span>
</xsl:template>

<xsl:template match="acronym">
	<acronym title="{@title}">
		<xsl:if test="@lang">
			<xsl:attribute name="lang">
				<xsl:value-of select="@lang"/>
			</xsl:attribute>
			<xsl:attribute name="xml:lang">
				<xsl:value-of select="@lang"/>
			</xsl:attribute>
		</xsl:if>
		
		<xsl:if test="@type">
			<xsl:attribute name="class">
				<xsl:value-of select="@type"/>
			</xsl:attribute>
		</xsl:if>
		
		<xsl:apply-templates/>
	</acronym>
</xsl:template>

<xsl:template match="directive">
	<xsl:comment>
		<xsl:text>#</xsl:text>
		<xsl:apply-templates/>
	</xsl:comment>
</xsl:template>

<xsl:template match="text()">
	<xsl:choose>
		<xsl:when test="parent::code">
			<xsl:value-of disable-output-escaping="no" select="."/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of disable-output-escaping="yes" select="."/>
		</xsl:otherwise>
	</xsl:choose>	
</xsl:template>

</xsl:stylesheet>
