<?xml version="1.0" encoding="utf-8" ?>

<!DOCTYPE stylesheet [
<!ENTITY sp "<xsl:text> </xsl:text>">
]>

<xsl:stylesheet
    version="2.0" 
    xmlns:r="http://xmlresume.sourceforge.net/resume/0.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
>
    <xsl:output method="xml" encoding="utf-8" />

    <xsl:param name="color_dark">#000</xsl:param>
    <xsl:param name="color_feature">darkorange</xsl:param>
    <xsl:param name="color_light">#CCC</xsl:param>
    <xsl:param name="color_link">#B72</xsl:param>
    <xsl:param name="color_link_under">#EB8</xsl:param>
    <xsl:param name="color_medium">#999</xsl:param>
    <xsl:param name="color_normal">#000</xsl:param>
    <xsl:param name="font_face_normal">Verdana</xsl:param>
    <xsl:param name="font_line_normal">9pt</xsl:param>
    <xsl:param name="font_margin_huge">0.315in</xsl:param>
    <xsl:param name="font_margin_normal">0.105in</xsl:param>
    <xsl:param name="font_margin_small">0.025in</xsl:param>
    <xsl:param name="font_margin_tiny">0.0075in</xsl:param>
    <xsl:param name="font_size_normal">7pt</xsl:param>
    <xsl:param name="font_size_dates">9pt</xsl:param>
    <xsl:param name="font_size_big">12pt</xsl:param>
    <xsl:param name="font_size_huge">18pt</xsl:param>
    <xsl:param name="font_size_gigantor">41pt</xsl:param>
    <xsl:param name="font_space_normal">0.03em</xsl:param>
    <xsl:param name="pos_column_left_left">0.4in</xsl:param>
    <xsl:param name="pos_column_center_left">1.4in</xsl:param>
    <xsl:param name="pos_column_content_top">1.57in</xsl:param>
    <xsl:param name="pos_column_right_top">0.6in</xsl:param>
    <xsl:param name="pos_column_right_left">5.9in</xsl:param>
    <xsl:param name="width_column_center">3.65in</xsl:param>
    <xsl:param name="width_column_center_split">1.6in</xsl:param>
    <xsl:param name="width_column_center_split_left">1.9in</xsl:param>
    <xsl:param name="width_column_content">5.05in</xsl:param>
       
    <!-- logo template -->
    <xsl:template name="logo">
        <xsl:param name="fname" />
        <xsl:param name="blurb" />
        <fo:block 
            color="{$color_feature}"
            font-size="{$font_size_gigantor}" 
            font-weight="bold" 
            letter-spacing="-0.09em"
            margin-left="-4pt"
            text-transform="uppercase" 
        >
            <xsl:value-of select="$fname" />
        </fo:block>
        <fo:block color="{$color_medium}" margin-top="-10pt">
            <xsl:value-of select="replace($blurb, 'Engineer &amp; ', '')" />
        </fo:block>
    </xsl:template>

    <!-- resume -->
    <xsl:template match="/r:resume">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="page1" page-height="10.5in" page-width="8in">
                    <fo:region-body margin-top="0in" margin-bottom="0in" />
                    <fo:region-before extent="0in" />
                    <fo:region-after extent="0in" />
                </fo:simple-page-master>
                <fo:simple-page-master master-name="page2" page-height="10.5in" page-width="8in">
                    <fo:region-body margin-top="0in" margin-bottom="0in" />
                    <fo:region-before extent="0in" />
                    <fo:region-after extent="0in" />
                </fo:simple-page-master>
                <fo:simple-page-master master-name="page3" page-height="10.5in" page-width="8in">
                    <fo:region-body margin-top="0in" margin-bottom="0in" />
                    <fo:region-before extent="0in" />
                    <fo:region-after extent="0in" />
                </fo:simple-page-master>
            </fo:layout-master-set>

            <!-- page1 -->
	    <fo:page-sequence master-reference="page1">
	        <fo:flow flow-name="xsl-region-body">
                    <!-- header wrapper -->
                    <fo:block-container 
                        absolute-position="absolute" 
                        top="{$pos_column_right_top}" 
                        left="{$pos_column_right_left}"
                        font-size="{$font_size_normal}" 
                        color="{$color_normal}"
                        font-family="{$font_face_normal}" 
                        letter-spacing="{$font_space_normal}"
                    >
        	        <xsl:apply-templates select="r:header" />
                    </fo:block-container>
                   
                    <!-- history wrapper -->
                    <fo:block-container 
                        absolute-position="absolute" 
                        top="{$pos_column_content_top}"
                        left="{$pos_column_left_left}" 
                        width="{$width_column_content}"
                        font-size="{$font_size_normal}" 
                        color="{$color_normal}"
                        font-family="{$font_face_normal}" 
                        letter-spacing="{$font_space_normal}"
                        border-top-style="solid"
                        border-top-width="thin"
                        border-top-color="#DDD"
                        padding-top="{$font_margin_normal}"
                    >
                        <fo:block-container
                            absolute-position="absolute" 
                            font-size="{$font_size_huge}"
                            font-weight="bold"
                            color="{$color_light}"
                        >
                            <fo:block>CAREER</fo:block>
                        </fo:block-container>
        
                        <fo:block-container
                            absolute-position="absolute" 
                            left="{$pos_column_center_left}"
                            width="{$width_column_center}"
                        >
                            <xsl:apply-templates select="r:history" />
                        </fo:block-container>
                    </fo:block-container>
                    
                </fo:flow>
	    </fo:page-sequence>
	   
            <!-- page2 -->
            <fo:page-sequence master-reference="page2">
	        <fo:flow flow-name="xsl-region-body">
                    <!-- header wrapper -->
                    <fo:block-container 
                        absolute-position="absolute" 
                        top="{$pos_column_right_top}" 
                        left="{$pos_column_right_left}"
                        font-size="{$font_size_normal}" 
                        color="{$color_normal}"
                        font-family="{$font_face_normal}" 
                        letter-spacing="{$font_space_normal}"
                    >
                        <xsl:call-template name="logo">
                            <xsl:with-param name="fname"><xsl:value-of select="/r:resume/r:header/r:name/r:firstname" /></xsl:with-param>
                            <xsl:with-param name="blurb">Resume Page 2 of 3</xsl:with-param>
                        </xsl:call-template>
                    </fo:block-container>
                    
                    <!-- skills wrapper -->
                    <fo:block-container 
                        absolute-position="absolute" 
                        top="{$pos_column_content_top}" 
                        left="{$pos_column_left_left}" 
                        width="{$width_column_content}"
                        font-size="{$font_size_normal}" 
                        color="{$color_normal}"
                        font-family="{$font_face_normal}" 
                        letter-spacing="{$font_space_normal}"
                        border-top-style="solid"
                        border-top-width="thin"
                        border-top-color="#DDD"
                        padding-top="{$font_margin_normal}"
                    >
                        <fo:block-container
                            absolute-position="absolute" 
                            font-size="{$font_size_huge}"
                            font-weight="bold"
                            color="{$color_light}"
                        >
                            <fo:block>SKILLS</fo:block>
                        </fo:block-container>
        
                        <fo:block-container
                            absolute-position="absolute" 
                            left="{$pos_column_center_left}"
                            width="{$width_column_center}"
                        >
                            <xsl:apply-templates select="r:skillareas" />
                        </fo:block-container>
                    </fo:block-container>
                    
	        </fo:flow>
            </fo:page-sequence>
            
            <!-- page3 -->
            <fo:page-sequence master-reference="page3">
	        <fo:flow flow-name="xsl-region-body">
                    <!-- header wrapper -->
                    <fo:block-container 
                        absolute-position="absolute" 
                        top="{$pos_column_right_top}" 
                        left="{$pos_column_right_left}"
                        font-size="{$font_size_normal}" 
                        color="{$color_normal}"
                        font-family="{$font_face_normal}" 
                        letter-spacing="{$font_space_normal}"
                    >
                        <xsl:call-template name="logo">
                            <xsl:with-param name="fname"><xsl:value-of select="/r:resume/r:header/r:name/r:firstname" /></xsl:with-param>
                            <xsl:with-param name="blurb">Resume Page 3 of 3</xsl:with-param>
                        </xsl:call-template>
                    </fo:block-container>
                    
                    <!-- effort wrapper -->
                    <fo:block-container 
                        absolute-position="absolute" 
                        top="{$pos_column_content_top}" 
                        left="{$pos_column_left_left}" 
                        width="{$width_column_content}"
                        font-size="{$font_size_normal}" 
                        color="{$color_normal}"
                        font-family="{$font_face_normal}" 
                        letter-spacing="{$font_space_normal}"
                        border-top-style="solid"
                        border-top-width="thin"
                        border-top-color="#DDD"
                        padding-top="{$font_margin_normal}"
                    >
                        <fo:block-container
                            absolute-position="absolute" 
                            font-size="{$font_size_huge}"
                            font-weight="bold"
                            color="{$color_light}"
                        >
                            <fo:block>EFFORT</fo:block>
                        </fo:block-container>
        
                        <fo:block-container
                            absolute-position="absolute" 
                            left="{$pos_column_center_left}"
                            width="{$width_column_center}"
                        >
                            <fo:block-container>
                                <xsl:apply-templates select="r:academics/r:degrees" />
                                <xsl:apply-templates select="r:memberships" />
                            </fo:block-container>
                            <fo:block-container margin-top="-2in">
                                <xsl:apply-templates select="r:awards" />
                                <xsl:call-template name="resumeinfo" />
                            </fo:block-container>
                        </fo:block-container>
                    </fo:block-container>
	        </fo:flow>
            </fo:page-sequence>
                    
        </fo:root>
    </xsl:template>

    <!-- header -->
    <xsl:template match="r:header">
        <xsl:call-template name="logo">
            <xsl:with-param name="fname"><xsl:value-of select="r:name/r:firstname" /></xsl:with-param>
            <xsl:with-param name="blurb"><xsl:value-of select="/r:resume/r:objective/r:para" /></xsl:with-param>
        </xsl:call-template>
        <fo:block 
            font-weight="bold" 
            color="{$color_dark}" 
            margin-top="{$font_margin_huge}" 
            margin-bottom="{$font_margin_normal}"
        >
            <xsl:value-of select="r:name/r:firstname" />&sp;
            <xsl:value-of select="r:name/r:surname" />
        </fo:block>
        <xsl:for-each select="r:contact/r:url"> 
            <fo:block margin-bottom="{$font_margin_tiny}">
                <xsl:element name="fo:basic-link">
                    <xsl:attribute name="color"><xsl:value-of select="$color_link" /></xsl:attribute>
                    <xsl:attribute name="border-bottom-color"><xsl:value-of select="$color_link_under" /></xsl:attribute>
                    <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
                    <xsl:attribute name="border-bottom-style">dotted</xsl:attribute>
                    <xsl:attribute name="external-destination">url(<xsl:value-of select="." />)</xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="contains(text(), 'linkedin')">LinkedIn Profile</xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="." />
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:element>
            </fo:block>
        </xsl:for-each>
        <fo:block margin-top="{$font_margin_normal}">
            <xsl:element name="fo:basic-link">
                <xsl:attribute name="color"><xsl:value-of select="$color_link" /></xsl:attribute>
                <xsl:attribute name="border-bottom-color"><xsl:value-of select="$color_link_under" /></xsl:attribute>
                <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
                <xsl:attribute name="border-bottom-style">dotted</xsl:attribute>
                <xsl:attribute name="external-destination">url(mailto:<xsl:value-of select="r:contact/r:email" />)</xsl:attribute>
                <xsl:value-of select="r:contact/r:email" />
            </xsl:element>
        </fo:block>
        <fo:block margin-top="{$font_margin_normal}">
            <xsl:value-of select="r:contact/r:phone" />
        </fo:block>
        <fo:block margin-top="{$font_margin_normal}">
            <xsl:value-of select="r:address/r:city" />, <xsl:value-of select="r:address/r:state" />
        </fo:block>
        <fo:block>
            <xsl:value-of select="r:address/r:country" />
        </fo:block>
        <fo:block margin-top="{$font_margin_normal}" color="{$color_medium}">
            <fo:block>PDF Version</fo:block>
            <fo:block>Last Updated:</fo:block>
            <fo:block>
                <xsl:value-of select="substring(/r:resume/r:lastModified/r:date/r:month, 1, 3)" />&sp;
                <xsl:value-of select="/r:resume/r:lastModified/r:date/r:year" /> 
            </fo:block>
        </fo:block>
    </xsl:template>
   
    <!-- job history -->
    <xsl:template match="r:history">
        <xsl:for-each select="r:job">
            <fo:block margin-bottom="{$font_margin_huge}">
                <fo:block color="{$color_feature}" font-size="{$font_size_big}" font-weight="bold" margin-left="-1pt">
                    <xsl:choose>
                        <xsl:when test="r:employer/r:link">
                            <xsl:element name="fo:basic-link">
                                <xsl:attribute name="color"><xsl:value-of select="$color_feature" /></xsl:attribute>
                                <xsl:attribute name="border-bottom-color"><xsl:value-of select="$color_link_under" /></xsl:attribute>
                                <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
                                <xsl:attribute name="border-bottom-style">dotted</xsl:attribute>
                                <xsl:attribute name="external-destination">url(<xsl:value-of select="r:employer/r:link/@href" />)</xsl:attribute>
                                <xsl:value-of select="r:employer/r:link" />
                            </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="r:employer" />
                        </xsl:otherwise>
                    </xsl:choose>
                </fo:block>
                <fo:block font-weight="bold">
                    <xsl:value-of select="r:jobtitle" />
                </fo:block>
                <fo:block-container relative-position="relative" text-align="right" padding-bottom="1pt" margin-top="-2pt">
                    <fo:block color="{$color_light}" font-size="{$font_size_dates}">
                        <xsl:value-of select="substring(r:period/r:from/r:date/r:month, 1, 3)" />&sp;
                        <xsl:value-of select="r:period/r:from/r:date/r:year" /> - 
                        <xsl:choose>
                            <xsl:when test="r:period/r:to/r:present">Present</xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="substring(r:period/r:to/r:date/r:month, 1, 3)" />&sp;
                                <xsl:value-of select="r:period/r:to/r:date/r:year" />
                            </xsl:otherwise>
                        </xsl:choose>
                    </fo:block>
                </fo:block-container>
                <fo:block color="{$color_medium}" margin-top="-{$font_size_dates}" margin-bottom="{$font_margin_small}">
                    <xsl:value-of select="r:location/r:city" />, <xsl:value-of select="r:location/r:state" />
                </fo:block>
                <fo:block line-height="{$font_line_normal}">
                    <xsl:for-each select="r:description/r:para/text()|r:description/r:para/*">
                        <xsl:choose>
                            <xsl:when test="self::*">
                                <xsl:element name="fo:basic-link">
                                    <xsl:attribute name="color"><xsl:value-of select="$color_link" /></xsl:attribute>
                                    <xsl:attribute name="border-bottom-color"><xsl:value-of select="$color_link_under" /></xsl:attribute>
                                    <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
                                    <xsl:attribute name="border-bottom-style">dotted</xsl:attribute>
                                    <xsl:attribute name="external-destination">url(<xsl:value-of select="@href" />)</xsl:attribute>
                                    <xsl:value-of select="." />
                                </xsl:element>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="." />
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:for-each>
                </fo:block> 
            </fo:block>
        </xsl:for-each>
    </xsl:template>
   
    <!-- skills -->
    <xsl:template match="r:skillareas">
        <xsl:for-each select="r:skillarea">
            <xsl:element name="fo:block-container">
                <xsl:attribute name="absolute-position">absolute</xsl:attribute>
                <xsl:attribute name="width"><xsl:value-of select="$width_column_center_split" /></xsl:attribute>
                <xsl:if test="position() = last()">
                    <xsl:attribute name="left"><xsl:value-of select="$width_column_center_split_left" /></xsl:attribute>
                </xsl:if>
                <fo:block color="{$color_feature}" font-size="{$font_size_big}" font-weight="bold" margin-bottom="{$font_margin_normal}" margin-left="-1pt">
                    <xsl:value-of select="r:title" />
                </fo:block>
                <xsl:for-each select="r:skillset">
                    <fo:block font-weight="bold">
                        <xsl:value-of select="r:title" />:
                    </fo:block>
                    <fo:block margin-bottom="{$font_margin_normal}">
                        <xsl:for-each select="r:skill">
                            <xsl:value-of select="." />
                            <xsl:if test="position() != last()">, </xsl:if>
                        </xsl:for-each>
                    </fo:block>
                </xsl:for-each>
            </xsl:element>
        </xsl:for-each>
    </xsl:template>
   
    <!-- education -->
    <xsl:template match="r:academics/r:degrees">
        <fo:block-container absolute-position="absolute" width="{$width_column_center_split}">
            <fo:block color="{$color_feature}" font-size="{$font_size_big}" font-weight="bold" margin-bottom="{$font_margin_normal}" margin-left="-1pt">
                School
            </fo:block>
            <xsl:for-each select="r:degree">
                <fo:block font-weight="bold">
                    <xsl:value-of select="r:date/r:year" />
                </fo:block>
                <fo:block margin-bottom="{$font_margin_normal}">
                    <xsl:value-of select="r:major" /> (<xsl:value-of select="r:level" />).
                    <xsl:if test="r:minor">
                        <xsl:value-of select="r:minor" /> Minor.
                    </xsl:if>
                    <xsl:element name="fo:basic-link">
                        <xsl:attribute name="color"><xsl:value-of select="$color_link" /></xsl:attribute>
                        <xsl:attribute name="border-bottom-color"><xsl:value-of select="$color_link_under" /></xsl:attribute>
                        <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
                        <xsl:attribute name="border-bottom-style">dotted</xsl:attribute>
                        <xsl:attribute name="external-destination">url(<xsl:value-of select="r:institution/r:link/@href" />)</xsl:attribute>
                        <xsl:value-of select="r:institution/r:link" />
                    </xsl:element>.
                    <xsl:value-of select="r:location/r:city" />, <xsl:value-of select="r:location/r:state" />.
                </fo:block>
            </xsl:for-each>
        </fo:block-container>
    </xsl:template>
   
    <!-- groups -->
    <xsl:template match="r:memberships">
        <fo:block-container absolute-position="absolute" width="{$width_column_center_split}" left="{$width_column_center_split_left}">
            <fo:block color="{$color_feature}" font-size="{$font_size_big}" font-weight="bold" margin-bottom="{$font_margin_normal}" margin-left="-1pt">
                Groups
            </fo:block>
            <xsl:for-each select="r:membership">
                <fo:block font-weight="bold">
                    <xsl:value-of select="r:date/r:year" />
                </fo:block>
                <fo:block margin-bottom="{$font_margin_normal}">
                    <xsl:choose>
                        <xsl:when test="r:organization/r:link">
                            <xsl:element name="fo:basic-link">
                                <xsl:attribute name="color"><xsl:value-of select="$color_link" /></xsl:attribute>
                                <xsl:attribute name="border-bottom-color"><xsl:value-of select="$color_link_under" /></xsl:attribute>
                                <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
                                <xsl:attribute name="border-bottom-style">dotted</xsl:attribute>
                                <xsl:attribute name="external-destination">url(<xsl:value-of select="r:organization/r:link/@href" />)</xsl:attribute>
                                <xsl:value-of select="r:organization/r:link" />
                            </xsl:element>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="r:organization" />
                        </xsl:otherwise>
                    </xsl:choose>.
                    <xsl:value-of select="r:title" />.
                    <xsl:value-of select="r:description/r:para" />.
                </fo:block>
            </xsl:for-each>
        </fo:block-container>
    </xsl:template>
   
    <!-- awards -->
    <xsl:template match="r:awards">
        <fo:block-container absolute-position="absolute" width="{$width_column_center_split}">
            <fo:block color="{$color_feature}" font-size="{$font_size_big}" font-weight="bold" margin-bottom="{$font_margin_normal}" margin-left="-1pt">
                Awards
            </fo:block>
            <xsl:for-each select="r:award">
                <fo:block font-weight="bold">
                    <xsl:value-of select="r:date/r:year" />
                </fo:block>
                <fo:block margin-bottom="{$font_margin_normal}">
                    <xsl:value-of select="r:title" />.
                    <xsl:if test="r:description/r:para"> 
                        <xsl:value-of select="r:description/r:para" />.
                    </xsl:if>
                    <xsl:element name="fo:basic-link">
                        <xsl:attribute name="color"><xsl:value-of select="$color_link" /></xsl:attribute>
                        <xsl:attribute name="border-bottom-color"><xsl:value-of select="$color_link_under" /></xsl:attribute>
                        <xsl:attribute name="border-bottom-width">thin</xsl:attribute>
                        <xsl:attribute name="border-bottom-style">dotted</xsl:attribute>
                        <xsl:attribute name="external-destination">url(<xsl:value-of select="r:organization/r:link/@href" />)</xsl:attribute>
                        <xsl:value-of select="r:organization/r:link" />
                    </xsl:element>.
                </fo:block>
            </xsl:for-each>
        </fo:block-container>
    </xsl:template>
    
    <!-- resume info -->
    <xsl:template name="resumeinfo">
        <fo:block-container absolute-position="absolute" width="{$width_column_center_split}" left="{$width_column_center_split_left}" color="{$color_medium}">
            <fo:block color="{$color_feature}" font-size="{$font_size_big}" font-weight="bold" margin-bottom="{$font_margin_normal}" margin-left="-1pt">
                Resume 
            </fo:block>
            <fo:block>
                This PDF was automatically generated via 
                <fo:basic-link
                    color="{$color_link}"
                    border-bottom-color="{$color_link_under}"
                    border-bottom-width="thin"
                    border-bottom-style="dotted"
                    external-destination="url(http://brev.name/resume/xsl/brev-resume-fo.xsl)">XSLT</fo:basic-link>
                from an 
                <fo:basic-link
                    color="{$color_link}"
                    border-bottom-color="{$color_link_under}"
                    border-bottom-width="thin"
                    border-bottom-style="dotted"
                    external-destination="url(http://brev.name/resume/brev-resume.xml)">XML</fo:basic-link>
                file in the 
                <fo:basic-link
                    color="{$color_link}"
                    border-bottom-color="{$color_link_under}"
                    border-bottom-width="thin"
                    border-bottom-style="dotted"
                    external-destination="url(http://xmlresume.sourceforge.net/)">XML Resume Library </fo:basic-link>
                format. 
            </fo:block>
        </fo:block-container>
    </xsl:template>

</xsl:stylesheet>
