<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fn="http://www.w3.org/2005/02/xpath-function">

<xsl:output method="text" />

<xsl:key name="month" match="month" use="@id"/>
<xsl:key name="person" match="person" use="@id"/>
<xsl:key name="org" match="org" use="@id"/>
<xsl:key name="pub" match="pub" use="@id"/>
<xsl:key name="event" match="event" use="@id"/>

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

<xsl:template match="cv">
\documentclass[11pt,oneside]{article}
\usepackage{resume_template}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now for the actual document:

\begin{document}

\fontfamily{ppl} \selectfont

% Name with horizontal rule
\bigname{<xsl:value-of select="name" />}

\vspace{-8pt} \rule{\textwidth}{1pt}

\vspace{-1pt} {\small {\itshape <xsl:value-of select="address1"/>} \\
	<xsl:value-of select="address2"/>}

\vspace{8 pt}

	\begin{ressection}{Objective}
		\resitem{<xsl:apply-templates select="objective"/>}
	\end{ressection}

	\begin{ressection}{Specialties}
		<xsl:for-each select="specialty">
			\begin{ressubsec}{<xsl:value-of select="name"/>}
			<xsl:for-each select="project">
				\item \textit{Project:} <xsl:value-of select="name"/> \texttt(<xsl:value-of select="url"/>)</xsl:for-each>
			\end{ressubsec}
		</xsl:for-each>
	\end{ressection}

	\begin{ressection}{Employment}
		<xsl:for-each select="job[important]">
			<xsl:call-template name="job" />
		</xsl:for-each>
	\end{ressection}

	\begin{ressection}{Education}
		<xsl:for-each select="degree[important]">
			<xsl:call-template name="degree" />
		</xsl:for-each>
	\end{ressection}

	\begin{ressection}{Software technologies}
		<xsl:apply-templates select="languages" />
	\end{ressection}

	\begin{ressection}{Academic honors}
		<xsl:apply-templates select="honors" />
	\end{ressection}

	\begin{ressection}{Publications}
		\resitem{<xsl:apply-templates select="pubSummary" />}
	\end{ressection}
\end{document}

</xsl:template>

<xsl:template match="when" name="when">
	<xsl:for-each select="start">
		<xsl:value-of select="month" />/<xsl:value-of select="year" /> --
	</xsl:for-each><xsl:for-each select="end_tbd">??</xsl:for-each><xsl:for-each select="end_present">present</xsl:for-each><xsl:for-each select="end">
		<xsl:value-of select="month" />/<xsl:value-of select="year" /><xsl:for-each select="tentative"> (expected)</xsl:for-each>
	</xsl:for-each><xsl:for-each select="summers">Summers, <xsl:value-of select="from" /> - <xsl:value-of select="to" />
	</xsl:for-each>
</xsl:template>

<xsl:template name="degree">
	\resitem{<xsl:for-each select="atOrg[1]">
		<xsl:for-each select="key('org', @org)">
			\textbf{<xsl:value-of select="name" />} \\
		</xsl:for-each>
	</xsl:for-each>\textbf{<xsl:value-of select="shortName" />},
	<xsl:for-each select="when"><xsl:call-template name="when" />, </xsl:for-each>
	<xsl:for-each select="gpa">GPA: <xsl:value-of select="text ()" /></xsl:for-each>}
</xsl:template>

<xsl:template match="author" name="author">
	<xsl:variable name="authorElem" select="." />
	<xsl:for-each select="key('person', @person)">
		<xsl:choose>
			<xsl:when test="authorElem/@as">
				<xsl:value-of select="$authorElem/@as" />
			</xsl:when>
			<xsl:when test="citeName">
				<xsl:value-of select="citeName" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="name" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>

<xsl:template name="month">
	<xsl:for-each select="key('month', month/@month)"><xsl:value-of select="name" /><xsl:text> </xsl:text></xsl:for-each>
</xsl:template>

<xsl:template name="org">
	<xsl:for-each select="key('org', @org)">
		<xsl:value-of select="name" />
		<xsl:for-each select="location">, <xsl:value-of select="text()" />
		</xsl:for-each>
		<xsl:for-each select="note"><xsl:text> </xsl:text><xsl:value-of select="text()" />
		</xsl:for-each>
	</xsl:for-each>
</xsl:template>

<xsl:template match="pubKind">
	<xsl:if test="not(dontShow)">
	\begin{ressection}{<xsl:value-of select="@name"/>}
		<xsl:apply-templates />
	\end{ressection}
	</xsl:if>
</xsl:template>

<xsl:template match="pub">
	\resitem{<xsl:for-each select="author[1]"><xsl:call-template name="author" /></xsl:for-each>
	<xsl:for-each select="author[position() > 1]">, <xsl:call-template name="author" /></xsl:for-each>.
	\textbf{<xsl:value-of select="title" />}. 
	<xsl:for-each select="type"><xsl:value-of select="text()" />. </xsl:for-each>
	<xsl:for-each select="report">Technical Report <xsl:value-of select="text()" />. </xsl:for-each>
	<xsl:for-each select="proceedings">
		<xsl:for-each select="key('event', @event)">Proceedings of the <xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />)<xsl:for-each select="publisher"><xsl:for-each select="key('org', @org)">, <xsl:value-of select="name" /></xsl:for-each></xsl:for-each>
		</xsl:for-each>
		<xsl:if test="@lncs">, Lecture Notes in Computer Science <xsl:value-of select="@lncs" />, Springer-Verlag</xsl:if>. 
		<xsl:for-each select="key('event', @event)"><xsl:if test="year"><xsl:call-template name="month" /><xsl:value-of select="year" />. </xsl:if></xsl:for-each>
	</xsl:for-each>
	<xsl:for-each select="atOrg">
		<xsl:call-template name="org" />. 
	</xsl:for-each>
	<xsl:call-template name="month" />
	<xsl:for-each select="year">
		<xsl:value-of select="text()" />.
	</xsl:for-each>}
</xsl:template>

<xsl:template name="bosses">
	<xsl:choose><xsl:when test="@title"><xsl:value-of select="@title" /></xsl:when><xsl:otherwise>PIs</xsl:otherwise></xsl:choose>:
	<xsl:for-each select="boss[1]"><xsl:for-each select="key('person', @person)"><xsl:value-of select="name" /></xsl:for-each></xsl:for-each>
	<xsl:for-each select="boss[position() > 1]"><xsl:for-each select="key('person', @person)">, <xsl:value-of select="name" /></xsl:for-each></xsl:for-each>
</xsl:template>

<xsl:template name="job" match="job">
	\resitm{<xsl:value-of select="title" />}{,
	<xsl:value-of select="shortOrg" />,
	<xsl:for-each select="when"><xsl:call-template name="when" /></xsl:for-each>}
</xsl:template>

<xsl:template match="fromOrg" name="fromOrg">
	<xsl:call-template name="org" />,
</xsl:template>

<xsl:template match="year" name="year">
	<xsl:value-of select="text()" />
</xsl:template>

<xsl:template match="fellowship">
	<xsl:if test="important">
	\resitem{\textbf{<xsl:value-of select="name" />} winner, <xsl:for-each select="fromOrg"><xsl:call-template name="fromOrg" /></xsl:for-each><xsl:for-each select="year"><xsl:call-template name="year" /></xsl:for-each><xsl:for-each select="when"><xsl:call-template name="when" /></xsl:for-each>}
	</xsl:if>
</xsl:template>

<xsl:template match="fellowship_honorable">
	<xsl:if test="important">
	\resitem{Honorable Mention, \textbf{<xsl:value-of select="name" />} competition, <xsl:for-each select="fromOrg"><xsl:call-template name="fromOrg" /></xsl:for-each><xsl:for-each select="year"><xsl:call-template name="year" /></xsl:for-each><xsl:for-each select="when"><xsl:call-template name="when" /></xsl:for-each>}
	</xsl:if>
</xsl:template>

<xsl:template match="inducted">
	<xsl:if test="important">
	\resitem{Inducted into \textbf{<xsl:value-of select="name" />}}
	</xsl:if>
</xsl:template>

<xsl:template match="a">\textbf{<xsl:value-of select="text()" />} (<xsl:value-of select="@href" />)</xsl:template>

<xsl:template match="b">\textbf{<xsl:value-of select="text()" />}</xsl:template>

<xsl:template match="category">
	<xsl:if test="important">
	\resitem{\textbf{<xsl:value-of select="@shortName" />}: <xsl:apply-templates />}
	</xsl:if>
</xsl:template>

</xsl:stylesheet>
