<?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:key name="journal" match="journal" 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:for-each select="address">
<xsl:for-each select="office"><xsl:value-of select="text()" /> \\</xsl:for-each>
<xsl:for-each select="org"><xsl:value-of select="text()" /> \\</xsl:for-each>
<xsl:value-of select="city" /> \\
<xsl:value-of select="country" /> \\
<xsl:value-of select="email" /> \\
<xsl:value-of select="url" />
</xsl:for-each>}

\vspace{8 pt}

	\begin{ressection}{Research interests}
		<xsl:for-each select="interests">\resitem{<xsl:value-of select="text ()" />}</xsl:for-each>
	\end{ressection}

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

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

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

	\begin{ressection}{Professional service}
                <xsl:for-each select="service/role">
			\resitem{<xsl:for-each select="key('event', @event)"><xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />)</xsl:for-each>, <xsl:value-of select="@name"/>}
		</xsl:for-each>
		\resitem{External reviewer for: <xsl:for-each select="reviewed/for[1]">
			<xsl:for-each select="key('event', @event)"><xsl:value-of select="abbrev" /></xsl:for-each>
		</xsl:for-each><xsl:for-each select="reviewed/for[position() > 1]">,
			<xsl:for-each select="key('event', @event)"><xsl:value-of select="abbrev" /></xsl:for-each>
		</xsl:for-each>}
	\end{ressection}

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

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

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

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

	\begin{ressection}{Summer schools}
		<xsl:apply-templates select="summer_schools" />
	\end{ressection}

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

	\begin{ressection}{Other activities}
		<xsl:apply-templates select="activities" />
	\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 select="location">, <xsl:value-of select="text ()" /></xsl:for-each> \\
		</xsl:for-each>
	</xsl:for-each><xsl:for-each select="atOrg[position() > 1]">
		<xsl:for-each select="key('org', @org)">
			<xsl:value-of select="name" />
		</xsl:for-each> \\
	</xsl:for-each>\textbf{<xsl:value-of select="name" />} \\
	<xsl:for-each select="when"><xsl:call-template name="when" /></xsl:for-each> \\
	<xsl:for-each select="advisor"><xsl:for-each select="key('person', @person)">Advisor: <xsl:value-of select="name" /> \\</xsl:for-each></xsl:for-each><xsl:for-each select="gpa">Cumulative GPA: <xsl:value-of select="text ()" /> out of 4.0 \\</xsl:for-each><xsl:for-each select="thesis">
		<xsl:for-each select="key('pub', @pub)">
			Thesis: <xsl:value-of select="title" />
		</xsl:for-each> \\
	</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">
	\ressubitem{<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="journal">
		<xsl:for-each select="key('journal', @journal)">
			<xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />).
		</xsl:for-each>
                <xsl:value-of select="@volume"/>. <xsl:value-of select="@pages"/>, <xsl:value-of select="@year"/>.
		<xsl:for-each select="key('journal', @journal)">
			<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: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:if test="status"><xsl:value-of select="status"/>.</xsl:if>}
</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:for-each select="atOrg">\\ <xsl:call-template name="org" /></xsl:for-each>
	<xsl:for-each select="when">\\ <xsl:call-template name="when" /></xsl:for-each>
	<xsl:for-each select="boss">\\ <xsl:choose><xsl:when test="@title"><xsl:value-of select="@title" /></xsl:when><xsl:otherwise>PI</xsl:otherwise></xsl:choose>: <xsl:for-each select="key('person', @person)"><xsl:value-of select="name" /></xsl:for-each></xsl:for-each>
	<xsl:for-each select="bosses">\\ <xsl:call-template name="bosses" /></xsl:for-each>}
</xsl:template>

<xsl:template match="fellowship">
	\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:template>

<xsl:template match="fellowship_honorable">
	\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: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="inducted">
	\resitem{Inducted into \textbf{<xsl:value-of select="name" />}}
</xsl:template>

<xsl:template match="summer_school">
	\resitem{\textbf{<xsl:value-of select="name" />}, <xsl:for-each select="atOrg"><xsl:call-template name="org" />, </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:template>

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

<xsl:template match="activity">
	\resitem{<xsl:apply-templates />}
</xsl:template>

<xsl:template match="program">
	\resitem{<xsl:apply-templates />}
</xsl:template>

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

<xsl:template match="talk">
	\resitem{``<xsl:value-of select="title" />.'' <xsl:for-each select="key('event', @event)"><xsl:value-of select="abbrev" />. <xsl:if test="year"><xsl:call-template name="month" /> <xsl:value-of select="year" />.</xsl:if></xsl:for-each>}
</xsl:template>

</xsl:stylesheet>
