<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
				xmlns:fo="http://www.w3.org/1999/XSL/Format"
				xmlns:svg="http://www.w3.org/2000/svg"
                version="1.0"
                exclude-result-prefixes="fo svg">

<xsl:output indent="yes"  encoding="ISO-8859-1" media-type="text/xml; charset=ISO-8859-15" method="xml" omit-xml-declaration="no" standalone="yes" version="1.0" />

<xsl:include href="cv_MarkWatkins_Common.xml" />

<xsl:variable name="destination" select="'fo'" />
<xsl:variable name="table" select="'fo:table'" />
<xsl:variable name="tablehead" select="'fo:table-header'" />
<xsl:variable name="tablebody" select="'fo:table-body'" />
<xsl:variable name="tablerow" select="'fo:table-row'" />
<xsl:variable name="tablecell" select="'fo:table-cell'" />
<xsl:variable name="tablecellhead" select="'fo:table-cell'" />
<xsl:variable name="block" select="'fo:block'" />
<xsl:variable name="inline" select="'fo:inline'" />

<xsl:variable name="marginleft" select="'margin-left'" />
<xsl:variable name="align" select="'text-align'" />



<xsl:template match="cv" name="cv">
<fo:root><!-- Not supported yet media-usage="paginate" -->

<!-- This defines the paper size and all the regions used in the rest of the document -->
<fo:layout-master-set>
	<fo:simple-page-master master-name="cv" page-height="29.7cm" page-width="21cm"
			margin-top=".5cm" margin-bottom=".5cm" margin-left="1.25cm" margin-right="1.25cm">
		<fo:region-body display-align="center" margin-top="1cm" margin-bottom="1cm" margin-left=".5cm" margin-right=".5cm" precedence="false" />
		<fo:region-before display-align="center" extent="1.5cm" precedence="true" />
		<fo:region-after display-align="center" extent="1.25cm" precedence="true" />
	</fo:simple-page-master>
</fo:layout-master-set>

<!-- This contains the rest of the document -->
<fo:page-sequence master-reference="cv" font-size="12pt"> <!-- Default is font-size="12pt" --><!-- This matches the XSL:FO standard for FOP.0.20.3+ - change from master-reference to master-name to work with FOP.0.20.1 -->
	<fo:title><xsl:value-of select="title" /></fo:title>
	<!-- This defines the header -->
    <fo:static-content flow-name="xsl-region-before">
           <fo:table>
           		<fo:table-column column-width="9.25cm" />
           		<fo:table-column column-width="9.25cm" />

				<fo:table-body>
					<fo:table-row>
						<fo:table-cell><fo:block font-weight="bold" font-size="10pt" font-family="serif"><xsl:call-template name="headfoot"><xsl:with-param name="hflr" select="headerleft" /></xsl:call-template></fo:block></fo:table-cell>
						<fo:table-cell><fo:block text-align="end" font-weight="bold" font-size="10pt" font-family="serif"><xsl:call-template name="headfoot"><xsl:with-param name="hflr" select="headerright" /></xsl:call-template></fo:block>
	        			</fo:table-cell>
	        		</fo:table-row>
	        	</fo:table-body>
	        </fo:table>
    </fo:static-content> 

    <fo:static-content flow-name="xsl-region-after">
           <fo:table>
           		<fo:table-column column-width="9.25cm" />
           		<fo:table-column column-width="9.25cm" />

				<fo:table-body>
					<fo:table-row>
						<fo:table-cell><fo:block font-weight="bold" font-size="10pt" font-family="serif"><xsl:call-template name="headfoot"><xsl:with-param name="hflr" select="footerleft" /></xsl:call-template></fo:block></fo:table-cell>
						<fo:table-cell><fo:block text-align="end" font-weight="bold" font-size="10pt" font-family="serif"><xsl:call-template name="headfoot"><xsl:with-param name="hflr" select="footerright" /></xsl:call-template></fo:block>
	        			</fo:table-cell>
	        		</fo:table-row>
	        	</fo:table-body>
	        </fo:table>
    </fo:static-content> 

	<!-- This holds the main content -->
	<fo:flow flow-name="xsl-region-body">
		<xsl:apply-templates select="vitalstats" />
		<xsl:apply-templates select="experience[@type='positions']" />
		<xsl:apply-templates select="experience[@type='products']" />
		<xsl:apply-templates select="experience[@type='education']" />
		<xsl:apply-templates select="experience[@type='positions']/pastwork" />
		<xsl:apply-templates select="experience[@type='leisure']" />
		<xsl:call-template name="references" />
		<fo:block id="TheEnd" />
	</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>

<xsl:template name="headfoot">
<xsl:param name="hflr" />
	<xsl:apply-templates select="$hflr" />
</xsl:template>

<xsl:template match="institle">
	<xsl:value-of select="/cv/title" />
</xsl:template>

<xsl:template match="inspages">
	<!--Page <fo:page-number /> of <fo:page-number-citation ref-id="TheEnd" />--><!-- Good for all but PS -->
	Page <fo:page-number /> of 2<!-- Good for PS (need to count pages manually) -->
</xsl:template>

<xsl:template name="tableattr" />

<xsl:template name="attribs">
<xsl:param name="attribs" />
	<xsl:if test="contains($attribs, 'indent')"><xsl:attribute name="start-indent">1cm</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'bold')"><xsl:attribute name="font-weight">bold</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'italic')"><xsl:attribute name="font-style">italic</xsl:attribute></xsl:if>
	<!-- rename the attribute, or leave it commented out for FO <xsl:if test="contains($attribs, 'nowrap')"><xsl:attribute name="white-space">nowrap</xsl:attribute></xsl:if>-->
	<xsl:if test="contains($attribs, 'mtop')"><xsl:attribute name="space-before.optimum">1cm</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'mbottom')"><xsl:attribute name="space-after.optimum">1cm</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'tleft')"><xsl:attribute name="text-align">start</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'tright')"><xsl:attribute name="text-align">end</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'tjustify')"><xsl:attribute name="text-align">justify</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'tcenter')"><xsl:attribute name="text-align">center</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'top')"><xsl:attribute name="vertical-align">top</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'bottom')"><xsl:attribute name="vertical-align">bottom</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'padl')"><xsl:attribute name="padding-left">.1cm</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'padr')"><xsl:attribute name="padding-right">.1cm</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'padt')"><xsl:attribute name="padding-top">.1cm</xsl:attribute></xsl:if>
	<xsl:if test="contains($attribs, 'padb')"><xsl:attribute name="padding-bottom">.1cm</xsl:attribute></xsl:if>
</xsl:template>


<xsl:template name="cell">
<xsl:param name="attribs" />
<xsl:param name="align">l</xsl:param>
<xsl:param name="bold">0</xsl:param>
<xsl:param name="italic">0</xsl:param>
<xsl:param name="nowrap">0</xsl:param>
<xsl:param name="pad">0</xsl:param>
<xsl:param name="content" />
<xsl:param name="rowspan" />
<xsl:param name="colspan" />

	<xsl:variable name="text-align">
		<xsl:choose>
			<xsl:when test="$align='l'">start</xsl:when>
			<xsl:when test="$align='r'">end</xsl:when>
			<xsl:when test="$align='j'">justify</xsl:when>
			<xsl:when test="$align='c'">center</xsl:when>
		</xsl:choose>
	</xsl:variable>

	<xsl:variable name="attr">
		<xsl:value-of select="$attribs" />
		<xsl:if test="$bold != 0">bold</xsl:if>
		<xsl:if test="$italic != 0">italic</xsl:if>
		<xsl:if test="$nowrap != 0">nowrap</xsl:if>
		<xsl:if test="$italic != 0">italic</xsl:if>
		<xsl:choose>
			<xsl:when test="$text-align = 'start'">tleft</xsl:when>
			<xsl:when test="$text-align = 'end'">tright</xsl:when>
			<xsl:when test="$text-align = 'justify'">tjustify</xsl:when>
			<xsl:when test="$text-align = 'center'">tcenter</xsl:when>
		</xsl:choose>
	</xsl:variable>

	<fo:table-cell>
		<xsl:call-template name="attribs"><xsl:with-param name="attribs" select="$attr" /></xsl:call-template>
		<xsl:if test="$rowspan and $rowspan &gt; 1"><xsl:attribute name="number-rows-spanned"><xsl:value-of select="$rowspan" /></xsl:attribute></xsl:if>
		<xsl:if test="$colspan and $colspan &gt; 1"><xsl:attribute name="number-columns-spanned"><xsl:value-of select="$colspan" /></xsl:attribute></xsl:if>
		<fo:block>
			<xsl:call-template name="attribs"><xsl:with-param name="attribs" select="$attr" /></xsl:call-template>
<!--			<xsl:if test="$bold!=0"><xsl:attribute name="font-weight">bold</xsl:attribute></xsl:if>
			<xsl:if test="$italic!=0"><xsl:attribute name="font-style">italic</xsl:attribute></xsl:if>
			<xsl:if test="string-length($text-align) &gt; 0"><xsl:attribute name="text-align"><xsl:value-of select="$text-align" /></xsl:attribute></xsl:if>
-->			<xsl:copy-of select="$content" />
		</fo:block>
	</fo:table-cell>
</xsl:template>


<xsl:template name="cellhead">
<xsl:param name="attribs" />
<xsl:param name="align">l</xsl:param>
<xsl:param name="bold">0</xsl:param>
<xsl:param name="italic">0</xsl:param>
<xsl:param name="nowrap">0</xsl:param>
<xsl:param name="pad">0</xsl:param>
<xsl:param name="content" />
<xsl:param name="rowspan" />
<xsl:param name="colspan" />

	<xsl:call-template name="cell">
		<xsl:with-param name="attribs" select="$attribs" />
		<xsl:with-param name="align" select="$align" />
		<xsl:with-param name="bold" select="$bold" />
		<xsl:with-param name="italic" select="$italic" />
		<xsl:with-param name="nowrap" select="$nowrap" />
		<xsl:with-param name="pad" select="$pad" />
		<xsl:with-param name="content" select="$content" />
		<xsl:with-param name="rowspan" select="$rowspan" />
		<xsl:with-param name="colspan" select="$colspan" />
	</xsl:call-template>
</xsl:template>


<xsl:template name="heading1">
<xsl:param name="title" />
<xsl:param name="moretitle" />
	<xsl:variable name="t"><xsl:choose><xsl:when test="string-length($title) &gt; 0"><xsl:value-of select="$title" /></xsl:when><xsl:otherwise><xsl:value-of select="@title" /></xsl:otherwise></xsl:choose></xsl:variable>
	<xsl:variable name="mt"><xsl:choose><xsl:when test="string-length($moretitle) &gt; 0"><xsl:value-of select="$moretitle" /></xsl:when><xsl:otherwise><xsl:value-of select="@moretitle" /></xsl:otherwise></xsl:choose></xsl:variable>
	<xsl:call-template name="heading">
		<xsl:with-param name="title" select="$t" />
		<xsl:with-param name="moretitle" select="$mt" />
		<xsl:with-param name="size" select="'18pt'" />
	</xsl:call-template>
</xsl:template>


<xsl:template name="heading2">
<xsl:param name="title" />
<xsl:param name="moretitle" />
<xsl:param name="righttext" />
	<xsl:variable name="t"><xsl:choose><xsl:when test="string-length($title) &gt; 0"><xsl:value-of select="$title" /></xsl:when><xsl:otherwise><xsl:value-of select="@title" /></xsl:otherwise></xsl:choose></xsl:variable>
	<xsl:variable name="mt"><xsl:choose><xsl:when test="string-length($moretitle) &gt; 0"><xsl:value-of select="$moretitle" /></xsl:when><xsl:otherwise><xsl:value-of select="@moretitle" /></xsl:otherwise></xsl:choose></xsl:variable>
	<xsl:call-template name="heading">
		<xsl:with-param name="title" select="$t" />
		<xsl:with-param name="moretitle" select="$mt" />
		<xsl:with-param name="size" select="'13pt'" />
		<xsl:with-param name="righttext" select="$righttext" />
	</xsl:call-template>
</xsl:template>


<xsl:template name="heading">
<xsl:param name="title" />
<xsl:param name="moretitle" />
<xsl:param name="righttext" />
<xsl:param name="size">13pt</xsl:param>
	<xsl:variable name="t"><xsl:choose><xsl:when test="string-length($title) &gt; 0"><xsl:value-of select="$title" /></xsl:when><xsl:otherwise><xsl:value-of select="@title" /></xsl:otherwise></xsl:choose></xsl:variable>
	<xsl:variable name="mt"><xsl:choose><xsl:when test="string-length($moretitle) &gt; 0"><xsl:value-of select="$moretitle" /></xsl:when><xsl:otherwise><xsl:value-of select="@moretitle" /></xsl:otherwise></xsl:choose></xsl:variable>
	<fo:block text-align="center" space-before.optimum=".35cm" space-after.optimum=".2cm" keep-with-next="always">
		<fo:inline color="maroon" font-weight="bold" font-size="{$size}"><xsl:value-of select="$t" /></fo:inline>
		<xsl:if test="string-length($mt) &gt; 0">, <xsl:value-of select="$mt" /></xsl:if>
		<xsl:if test="string-length($righttext) &gt; 0"><fo:inline margin-left="5em"><xsl:value-of select="$righttext" /></fo:inline></xsl:if>
	</fo:block>
</xsl:template>


<xsl:template name="subhead">
<xsl:param name="title" />
<xsl:param name="moretitle" />
	<xsl:variable name="t"><xsl:choose><xsl:when test="string-length($title) &gt; 0"><xsl:copy-of select="$title" /></xsl:when><xsl:otherwise><xsl:value-of select="@title" /></xsl:otherwise></xsl:choose></xsl:variable>
	<xsl:variable name="mt"><xsl:choose><xsl:when test="string-length($moretitle) &gt; 0"><xsl:copy-of select="$moretitle" /></xsl:when><xsl:otherwise><xsl:value-of select="@moretitle" /></xsl:otherwise></xsl:choose></xsl:variable>
	<fo:block text-align="start" start-indent="1cm" space-before.optimum=".1cm" keep-with-next="always"><fo:inline font-weight="bold"><xsl:copy-of select="$t" /></fo:inline><xsl:if test="string-length($mt) &gt; 0"> - <fo:inline font-size="9pt"><xsl:copy-of select="$mt" /></fo:inline></xsl:if></fo:block>
</xsl:template>


<xsl:template name="link">
<xsl:param name="url" />
<xsl:param name="description" />
<xsl:param name="title" /><!-- This param is unused in the FO generation, but is in the HTML -->
	<xsl:variable name="desc1">
		<xsl:choose>
			<xsl:when test="starts-with($description, 'http://')"><xsl:value-of select="substring-after($description, 'http://')" /></xsl:when>
			<xsl:otherwise><xsl:value-of select="$description" /></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="desc">
		<xsl:choose>
			<xsl:when test="substring($desc1, string-length($desc1), 1) = '/'"><xsl:value-of select="substring($desc1, 1, string-length($desc1) - 1)" /></xsl:when>
			<xsl:otherwise><xsl:value-of select="$desc1" /></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<fo:basic-link external-destination="{$url}" color="navy"><xsl:value-of select="$desc" /></fo:basic-link>
</xsl:template>


<xsl:template name="acronym">
<xsl:param name="short" />
<xsl:param name="long" /><!-- not used for the FO version -->
	<xsl:value-of select="$short" />
</xsl:template>


<xsl:template name="abbrev">
<xsl:param name="short" />
<xsl:param name="long" /><!-- not used for the FO version -->
	<xsl:value-of select="$short" />
</xsl:template>


<xsl:template name="img">
<xsl:param name="src" />
<xsl:param name="x" />
<xsl:param name="y" />
<xsl:param name="xcm" />
<xsl:param name="ycm" />
<xsl:param name="description" />
	<xsl:if test="string-length($src) &gt; 0">
		<fo:external-graphic src="{$src}" width="{$xcm}" height="{$ycm}" />
	</xsl:if>
</xsl:template>

</xsl:stylesheet>