<?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:import href="main.xsl"/>

<xsl:template match="related">
	<xsl:if test="project">
		<h5>Featured Projects</h5>
		<ul class="links">
			<xsl:apply-templates select="project[@type='project']" mode="sidebar">
				<xsl:sort select="@year" data-type="number" order="descending"/>
				<xsl:sort select="@month" data-type="number" order="descending"/>
				<xsl:sort select="@name"/>
			</xsl:apply-templates>
		</ul>
		<h5>Free Software</h5>
		<ul class="links">
			<xsl:apply-templates select="project[@type='code']" mode="sidebar">
				<xsl:sort select="@name"/>
			</xsl:apply-templates>
		</ul>
	</xsl:if>
</xsl:template>

<xsl:template match="related" mode="head">
	<xsl:apply-templates select="section[@type='project']" mode="work-head">
		<xsl:sort select="@year" data-type="number" order="descending"/>
		<xsl:sort select="@month" data-type="number" order="descending"/>
		<xsl:sort select="@title"/>
	</xsl:apply-templates>
	<xsl:apply-templates select="section[@type='code']" mode="work-head">
		<xsl:sort select="@title"/>
	</xsl:apply-templates>
	<xsl:apply-imports/>
</xsl:template>

<xsl:template match="related/section" mode="work-head">
	<xsl:call-template name="link-generator">
		<xsl:with-param name="title">
			<xsl:call-template name="capitalizor">
				<xsl:with-param name="text" select="@title"/>
			</xsl:call-template>
		</xsl:with-param>
		<xsl:with-param name="target">
			<xsl:text>/work/</xsl:text>
			<xsl:value-of select="@path"/>
			<xsl:text>/</xsl:text>
		</xsl:with-param>
		<xsl:with-param name="rel">section</xsl:with-param>
		<xsl:with-param name="type">text/html</xsl:with-param>
	</xsl:call-template>
</xsl:template>

<xsl:template match="related/project" mode="sidebar">
	<li>
		<xsl:choose>
			<xsl:when test="/page/content/project and @path = /page/content/project/@path">
				<xsl:attribute name="id">active</xsl:attribute>
				<xsl:value-of select="@name"/>
			</xsl:when>
			<xsl:otherwise>
				<a>
					<xsl:attribute name="href">
						<xsl:call-template name="target-handler">
							<xsl:with-param name="target">
								<xsl:text>/work/</xsl:text>
								<xsl:value-of select="@path"/>
								<xsl:text>/</xsl:text>
							</xsl:with-param>
						</xsl:call-template>
					</xsl:attribute>
					<xsl:value-of select="@name"/>
				</a>
			</xsl:otherwise>
		</xsl:choose>
	</li>
</xsl:template>

</xsl:stylesheet>

