<?xml version='1.0' encoding='ISO-8859-1' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <!-- variables -->
    <xsl:variable name="img-width" select="30"/>
    <xsl:variable name="img-height" select="40"/>
    <!-- Topmost template -->
    <xsl:template match="resume">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="MainPage">
                    <fo:region-body margin="0.4in" padding="0.2in"/>
                    <fo:region-before extent="0.8in" padding="0.2in"/>
                    <fo:region-after extent="0.8in" padding="0.2in"/>
                </fo:simple-page-master>
                <fo:page-sequence-master master-name="Repeat-MainPages">
                    <fo:repeatable-page-master-reference master-reference="MainPage"/>
                </fo:page-sequence-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="Repeat-MainPages">
                <!-- page numbers -->
                <fo:static-content flow-name="xsl-region-after">
                    <fo:block text-align="center" font-size="10pt">&#x2014; <fo:page-number/> &#x2014;</fo:block>
                </fo:static-content>
                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="12pt">
                        <xsl:apply-templates select="*"/>
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
    <!-- Captions output -->
    <xsl:template name="caption">
        <fo:block font="bold 10pt Helvetica" keep-together.within-column="always"
            keep-with-next.within-column="always" space-before.minimum="6pt"
            space-before.optimum="12pt" space-before.conditionality="retain"
            space-after.optimum="5pt" padding-top="3pt" padding-left="4pt" background-color="#EFEFEF">
            <fo:inline>
                <xsl:value-of select="@caption"/>
            </fo:inline>
        </fo:block>
    </xsl:template>
    <!-- Labels output  -->
    <xsl:template name="Label">
        <fo:inline font-weight="bold" font-family="Times" margin-right="0.03in">
            <xsl:value-of select="@label"/>
        </fo:inline>
    </xsl:template>
    <!-- Contact information -->
    <xsl:template match="contact-info">
        <fo:table space-before.optimum="6pt" space-after.optimum="6pt" padding="2pt" font-family="Times">
            <fo:table-column column-width="3in"/>
            <fo:table-header text-align="left" font-size="10pt">
                <fo:table-cell>
                    <fo:block>
                        <xsl:apply-templates select="address|telephones|mobile|faxes|emails|sponsored-links"/>
                    </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                    <fo:block>
                        <xsl:apply-templates select="photo"/>
                    </fo:block>
                </fo:table-cell>
            </fo:table-header>
            <fo:table-body>
                <fo:table-cell number-columns-spanned="2" padding-top="0.2in" text-align="center"
                    font-size="23pt" font-weight="bold">
                    <fo:block>
                        <fo:inline padding-right="0.025in">
                            <xsl:value-of select="//firstname"/>
                        </fo:inline>
                        <fo:inline padding-left="0.025in">
                            <xsl:value-of select="//surname"/>
                        </fo:inline>
                    </fo:block>
                </fo:table-cell>
            </fo:table-body>
        </fo:table>
    </xsl:template>
    <xsl:template match="photo">
        <fo:block>
            <xsl:choose>
                <xsl:when test="@src">
                    <fo:external-graphic src="url('{@src}')" content-width="{$img-width}mm" content-height="{$img-height}mm"/>
                </xsl:when>
            </xsl:choose>
        </fo:block>
    </xsl:template>
    <xsl:template match="address|telephones|mobile|faxes|emails|sponsored-links">
        <fo:block>
            <xsl:call-template name="Label"/>
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="apartament">
        <fo:wrapper>
            <xsl:apply-templates/>, </fo:wrapper>
    </xsl:template>
    <xsl:template match="city|state|country">
        <fo:wrapper padding-right="0.03in">
            <xsl:apply-templates/>, </fo:wrapper>
    </xsl:template>
    <xsl:template match="housenumber">
        <fo:wrapper>
            <xsl:apply-templates/>
            <xsl:choose>
                <xsl:when test="//apartament != &quot;&quot;">/</xsl:when>
            </xsl:choose>
        </fo:wrapper>
    </xsl:template>
    <xsl:template match="street|index|area-code|number|email|link">
        <fo:wrapper padding-right="0.03in">
            <xsl:apply-templates/>
        </fo:wrapper>
    </xsl:template>
    <xsl:template match="birth-date|birth-place|marital">
        <fo:block>
            <xsl:call-template name="Label"/>
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="personal-data|educations|awards|experiences|volunteer-works|skills|languages|publications|hobbies">
        <xsl:call-template name="caption"/>
        <xsl:apply-templates select="*"/>
    </xsl:template>
    <xsl:template match="education|experience|volunteer-work">
        <fo:block padding-bottom="10pt">
            <fo:list-block provisional-distance-between-starts="2in" provisional-label-separation="0in">
                <fo:list-item>
                    <fo:list-item-label end-indent="label-end()">
                        <fo:block>
                            From <xsl:apply-templates select="from"/>
                        </fo:block>
                        <fo:block>
                            To <xsl:apply-templates select="to"/>
                        </fo:block>
                    </fo:list-item-label>
                    <fo:list-item-body start-indent="body-start()">
                        <fo:block>
                            <xsl:apply-templates select="degree|major|faculty|institution|position|responsibilities|place|additional-info|item|hobby|skill"/>
                        </fo:block>
                    </fo:list-item-body>
                </fo:list-item>
            </fo:list-block>
        </fo:block>
    </xsl:template>
    <xsl:template match="from|to">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="responsibility|language|item|hobby|skill|publication">
        <fo:list-block provisional-distance-between-starts="0.1in" provisional-label-separation="0in">
            <fo:list-item>
                <fo:list-item-label end-indent="label-end()">
                    <fo:block margin-left="0.2in">&#x2022;</fo:block>
                </fo:list-item-label>
                <fo:list-item-body start-indent="body-start()">
                    <fo:block margin-left="0.2in">
                        <xsl:apply-templates/>
                        <fo:inline>
                            <xsl:choose>
                                <xsl:when test="@level">
                                    <fo:inline>&#x2013; <xsl:value-of select="@level"/>
                                    </fo:inline>
                                </xsl:when>
                            </xsl:choose>
                        </fo:inline>
                    </fo:block>
                </fo:list-item-body>
            </fo:list-item>
        </fo:list-block>
    </xsl:template>
    <xsl:template match="degree|major|faculty|institution|position|responsibilities|place|additional-info">
        <fo:block>
            <xsl:choose>
                <xsl:when test="@label">
                    <xsl:call-template name="Label"/>
                </xsl:when>
            </xsl:choose>
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="other">
        <xsl:call-template name="caption"/>
        <xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>

