<?xml version="1.0"?>

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

<!-- Some attibute sets -->

<xsl:attribute-set name="default-font-attributes">
	<xsl:attribute name="face">HELVETICA, VERDANA, ARIAL</xsl:attribute>
	<xsl:attribute name="size">-1</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="section-title-font-attributes">
	<xsl:attribute name="face">HELVETICA, VERDANA, ARIAL</xsl:attribute>
	<xsl:attribute name="size">+1</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="subsection-title-font-attributes">
	<xsl:attribute name="face">HELVETICA, VERDANA, ARIAL</xsl:attribute>
	<xsl:attribute name="size">0</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="publication-font-attributes">
	<xsl:attribute name="face">HELVETICA, VERDANA, ARIAL</xsl:attribute>
	<xsl:attribute name="size">-2</xsl:attribute>
</xsl:attribute-set>

<xsl:attribute-set name="footer-font-attributes">
	<xsl:attribute name="face">HELVETICA, VERDANA, ARIAL</xsl:attribute>
	<xsl:attribute name="size">-3</xsl:attribute>
</xsl:attribute-set>

<!-- set up a rule that passes undefined elements (i.e. raw HTML) straight
through -->
<xsl:template match="*">
	<xsl:element name="{name(.)}">
	<xsl:for-each select="@*">
		<xsl:attribute name="{name(.)}">
			<xsl:value-of select="."/>
		</xsl:attribute>
	</xsl:for-each>
	<xsl:apply-templates/>
	</xsl:element>
</xsl:template>

<!-- Now the document-specific rules -->

<!-- use link tag for anchors -->
<xsl:template match="link">
	<xsl:element name="A">
		<xsl:attribute name="HREF">
				<xsl:value-of select="@url"/>
			</xsl:attribute>
         <xsl:apply-templates/>
</xsl:element>
</xsl:template>

<!-- redefine the <CODE> tag to switch to Courier font-->
<xsl:template match="code | CODE">
	<FONT FACE="COURIER">
	<xsl:apply-templates/>
	</FONT>
</xsl:template>

<!-- redefine the <TD> and <TH> tags to ensure that the contents of table
cells is in the right font -->
<xsl:template match="td | TD | th | TH">
	<xsl:element name="{name(.)}">
		<!-- copy through any attributes -->
		<xsl:for-each select="@*">
			<xsl:attribute name="{name(.)}">
				<xsl:value-of select="."/>
			</xsl:attribute>
		</xsl:for-each>
		<!-- wrap up the contents in the desired font -->
		<FONT xsl:use-attribute-sets="font-attributes">
		<xsl:apply-templates/>
		</FONT>
	</xsl:element>
</xsl:template>

<!-- The master rule that wraps up the entire document -->
<xsl:template match="squizz-cv">
	<HTML>

	<xsl:comment>
	This file was automatically generated from an XML source using an XSL
	stylesheet. Do NOT attempt to edit it. All changes will be lost.
	</xsl:comment>

	<xsl:comment>
	Note that accented character entities are not yet "properly" supported.
	</xsl:comment>

	<HEAD>

	<TITLE>
		<xsl:apply-templates select="header-title"/>
	</TITLE>
	</HEAD>

	<BODY
		BGCOLOR="WHITE"
		BGPROPERTIES="FIXED"
		TOPMARGIN="0"
		LEFTMARGIN="0"
	>

		<!-- BODY OF PAGE -->
		<xsl:apply-templates select="body"/>
		<!-- END BODY -->

		<CENTER>
		<HR NOSHADE="" SIZE="1" WIDTH="50%"/>
		<FONT xsl:use-attribute-sets="footer-font-attributes">
		Generated from XML source and an
		<A HREF="http://www.csse.monash.edu.au/~davids/xsl/squizz-cv.xsl">XSL
		stylesheet</A>,
		using <A HREF="http://xmlsoft.org/XSLT/">xsltproc</A>
		</FONT>
		</CENTER>
	</BODY>
	</HTML>
</xsl:template>

<!-- need some empty rules to avoid the default rule -->
<xsl:template match="text">
	<xsl:apply-templates/>
</xsl:template>

<!-- and some for which not even the font need be specified -->
<xsl:template match="last-update | header-title | page-title | qualifications | title | authors | where-published | publication-details | note">
	<xsl:apply-templates/>
</xsl:template>

<!-- everything other than the header information is in the body -->
<xsl:template match="body">
	<xsl:apply-templates select="personal-info"/>
	<!-- Short cuts: Level 1-->
	<TABLE WIDTH="100%" BGCOLOR="#E0E0FF" BORDER="1">
	<TR>
	<TD ALIGN="CENTER">
	<xsl:apply-templates select="//postscript-version"/>
	</TD>
	<TD ALIGN="CENTER">
	<xsl:apply-templates select="//pdf-version"/>
	</TD>
	</TR>
	</TABLE>
	<xsl:apply-templates select="contents"/>
</xsl:template>

<xsl:template match="postscript-version">
	<A HREF="{@url}">Postscript version</A>
</xsl:template>

<xsl:template match="pdf-version">
	<A HREF="{@url}">Adobe Acrobat version (PDF)</A>
</xsl:template>

<!-- this is used for the first part of personal pages. Most pages don't
contain personal-info -->
<xsl:template match="body/personal-info">
	<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="10" BORDER="0">
	<TR>
	<TD ALIGN="LEFT">
		<FONT xsl:use-attribute-sets="default-font-attributes">
		<H1><xsl:apply-templates select="name"/></H1>
		</FONT>
	</TD>
	<TD ALIGN="RIGHT">
		<FONT xsl:use-attribute-sets="default-font-attributes">
		<H1><xsl:apply-templates select="qualifications"/></H1>
		</FONT>
	</TD>
	</TR>
	<TR>
	<TD>
		<xsl:apply-templates select="photo"/>
	</TD>
	<TD VALIGN="TOP" WIDTH="80%">
		<FONT xsl:use-attribute-sets="default-font-attributes">
		<xsl:apply-templates select="citizenship"/>
		<xsl:apply-templates select="date-of-birth"/>
		<P>
		Last updated: <xsl:apply-templates select="../../last-update"/>
		</P>
		</FONT>
	</TD>
	</TR>
	</TABLE>
</xsl:template>

<xsl:template match="personal-info/photo">
	<CENTER>
	<IMG src="{@url}" width="{@width}" height="{@height}"/>
	</CENTER>
</xsl:template>

<!-- the contents is everything other than personal-info. Most pages have a
body which only contains "contents". -->
<xsl:template match="body/contents">
	<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="10" BORDER="0">
		<xsl:apply-templates/>
	</TABLE>
</xsl:template>

<xsl:template match="section">
	<TR>
	<TD COLSPAN="2">
	<HR NOSHADE="" SIZE="3"/>
	</TD>
	</TR>
	<TR>
	<TD VALIGN="TOP" WIDTH="20%">
		<xsl:apply-templates select="title"/>
	</TD>
	<TD VALIGN="TOP" WIDTH="80%">
	<FONT xsl:use-attribute-sets="default-font-attributes">
	<xsl:if test="itemize | text">
		<xsl:apply-templates select="itemize | text"/>
	</xsl:if>
	</FONT>
	</TD>
	</TR>
	<xsl:if test="subsection">
		<xsl:apply-templates select="subsection"/>
	</xsl:if>
</xsl:template>

<xsl:template match="section/title">
	<FONT xsl:use-attribute-sets="section-title-font-attributes">
	<STRONG>
	<xsl:if test="@url">
		<A HREF="{@url}">
		<xsl:apply-templates/>
		</A>
	</xsl:if>
	<xsl:if test="not(@url)">
		<xsl:apply-templates/>
	</xsl:if>
	</STRONG>
	</FONT>
</xsl:template>

<xsl:template match="subsection">
		<TR>
		<TD VALIGN="TOP" WIDTH="20%">
			<FONT xsl:use-attribute-sets="subsection-title-font-attributes">
			<xsl:apply-templates select="title"/>
			</FONT>
		</TD>
		<TD VALIGN="TOP" WIDTH="80%">
		<FONT xsl:use-attribute-sets="default-font-attributes">
		<xsl:if test="itemize | text | publication">
			<xsl:apply-templates select="itemize | text | publication"/>
		</xsl:if>
		</FONT>
		</TD>
		</TR>
</xsl:template>

<xsl:template match="subsection/title">
	<FONT xsl:use-attribute-sets="subsection-title-font-attributes">
	<STRONG>
	<xsl:if test="@url">
		<A HREF="{@url}">
		<xsl:apply-templates/>
		</A>
	</xsl:if>
	<xsl:if test="not(@url)">
		<xsl:apply-templates/>
	</xsl:if>
	</STRONG>
	</FONT>
</xsl:template>

<xsl:template match="publication">
	<FONT xsl:use-attribute-sets="publication-font-attributes">
	<xsl:value-of select="normalize-space(authors)"/>.&#160;
	<xsl:if test="@url">
		<A HREF="{@url}"><xsl:value-of select="normalize-space(title)"/></A>.&#160;
	</xsl:if>
	<xsl:if test="not(@url)">
		<xsl:value-of select="normalize-space(title)"/>.&#160;
	</xsl:if>
	<xsl:if test="where-published">
		<EM><xsl:value-of select="normalize-space(where-published)"/>,</EM>&#160;
	</xsl:if>
	<xsl:if test="publication-details">
		<xsl:value-of select="normalize-space(publication-details)"/>.&#160;
	</xsl:if>
	<xsl:if test="note">
		<xsl:value-of select="normalize-space(note)"/>.&#160;
	</xsl:if>
	</FONT>
	<P/>
</xsl:template>

<xsl:template match="itemize">
	<xsl:if test="@title">
		<STRONG>
		<xsl:value-of select="@title"/>
		</STRONG>
	</xsl:if>
	<UL>
		<xsl:for-each select="item">
			<LI>
			<xsl:apply-templates/>
			</LI>
		</xsl:for-each>
	</UL>
</xsl:template>

<xsl:template match="itemize/item/title">
	<STRONG>
	<xsl:apply-templates/>
	</STRONG>
</xsl:template>

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

<xsl:template match="date-of-birth">
	Born <xsl:apply-templates/>.
</xsl:template>

<!-- handle some really standard formatting stuff -->
<xsl:template match="bold">
	<STRONG><xsl:apply-templates/></STRONG>
</xsl:template>

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

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

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

<xsl:template match="linebreak">
	<BR/>
</xsl:template>
			
<xsl:template match="dollar">$</xsl:template>	

<xsl:template match="latex">LaTeX</xsl:template>

<xsl:template match="bibtex">BibTeX</xsl:template>

</xsl:stylesheet>

