﻿
<!DOCTYPE xsl:stylesheet [
    <!ENTITY nbsp "&#x00A0;"> 
]>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" 
        doctype-system="http://www.w3.org/TR/html4/loose.dtd"
        doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"
        encoding="UTF-8"
        omit-xml-declaration="yes"
        indent="yes"/>
    
    <xsl:param name="details_param"/>
    <xsl:param name="lang_param"/>

    <xsl:variable name="debug">0</xsl:variable>
    <xsl:variable name="lang">
        <xsl:choose>
            <xsl:when test="string-length($lang_param) = 0">fr</xsl:when>
            <xsl:otherwise><xsl:value-of select="$lang_param"/></xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="details">
        <xsl:choose>
            <xsl:when test="string-length($details_param) = 0">false</xsl:when>
            <xsl:otherwise>true</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template match="/resumes">
        <html>
          <head>
                <script type="text/javascript" src="cv.js" />
                <title><xsl:value-of select="/resumes/resume[@lang=$lang]/title/text()"/></title>
                <xsl:call-template name="style"/>
            </head>
            <body style="margin:0px">
                <table class="options" id="options" width="100%"><tr>
                        <td><xsl:call-template name="options"/></td>
                 <!--</div>
                 <div class="options" id="options" align="right">-->
                        <td align="right"><xsl:call-template name="languages" /></td>
                 </tr></table>
                
                <xsl:apply-templates select="./resume[@lang = $lang]"/>
                <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
                <script src="http://www.bouleis.fr/wp-content/plugins/google-analyticator/ga_external-links.js" type="text/javascript"></script>
                <script type="text/javascript">
                    onContent(function() {
                        urchin = new urchin();
                        urchin.trackDownload = "pdf|jar";
                        urchin.trackLinks();
                    } );
                    _uacct="UA-1734900-1";  urchinTracker();
                </script>
            </body>
        </html>
    </xsl:template>
    
    <xsl:template match="resume">
        <table border="{$debug}" class="maintable" cellpadding="0" cellspacing="0">
            <tr><td style="width:100%">
                <div><xsl:call-template name="head" /></div>
            </td></tr>
            <tr><td>
                    <xsl:apply-templates select="section"/>
            </td></tr>
        </table>
    </xsl:template>
    
    <xsl:template name="head">
        <table border="{$debug}" style="width:100%" cellpadding="0" cellspacing="0">
            <tr>
                <td valign="top">
                   <div class="coords">
                       <xsl:value-of select="./coords/name/text()"/><br />
                       <xsl:value-of select="./coords/address/text()"/><br />
                       <xsl:value-of select="./coords/phone[@type = 'mobile']/text()"/><br />
                       <xsl:value-of select="./coords/mail/text()"/><br />
                       <xsl:value-of select="./coords/web/text()"/><br />
                       <br />
                       <xsl:for-each select="./divers">
                           <xsl:value-of select="./text()"/><br />
                       </xsl:for-each>
                    </div> 
                </td>
                <td>
                    <div class="title"><xsl:value-of select="./title/text()"/></div>
                </td>
                <td align="right">
                    <div><img width="100" src="{./coords/photoURL/text()}" alt="{./coords/name/text()}" /></div>
                </td>
            </tr>
        </table>
    </xsl:template>
    
    <xsl:template match="section">
        <xsl:variable name="id">
            <xsl:choose>
                <xsl:when test="./@display = 'false'">variable_display_<xsl:value-of select="position()"/></xsl:when>
                <xsl:otherwise>always_display_<xsl:value-of select="position()"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        
        <xsl:variable name="style">
            <xsl:choose>
                <xsl:when test="./@display = 'false'">display:none;</xsl:when>
                <xsl:otherwise>display:block;<xsl:value-of select="position()"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        
        <div id="{$id}" style="{$style}">
            <table border="{$debug}" width="100%" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                        <div  class="h1"><h1><xsl:value-of select="./title/text()"/></h1></div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="section"><table class="section" cellpadding="0" cellspacing="0" width="100%">
                            <xsl:apply-templates select="position | entry">
                                <xsl:with-param name="parentPosition"><xsl:value-of select="position()"/></xsl:with-param>
                            </xsl:apply-templates>
                        </table></div>
                    </td>
                </tr>
            </table>
        </div>
    </xsl:template>
    
    <xsl:template match="position | entry" >
        <xsl:param name="parentPosition"/>
        
        <xsl:variable name="textColspan">
            <xsl:choose>
                <xsl:when test="name() = 'entry'">1</xsl:when>
                <xsl:otherwise>2</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        
        <xsl:variable name="id">
            <xsl:choose>
                <xsl:when test="./@display = 'false'">variable_display_<xsl:value-of select="$parentPosition"/>_<xsl:value-of select="position()"/></xsl:when>
                <xsl:otherwise>always_display_<xsl:value-of select="$parentPosition"/>_<xsl:value-of select="position()"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        
        <xsl:variable name="style">
            <xsl:choose>
                <xsl:when test="./@display = 'false'">display:none</xsl:when>
                <xsl:otherwise>display:block</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        
        <tr >
            <td style="width:100%">
                <div id="{$id}" style="{$style}">
                    <xsl:variable name="position"><xsl:value-of select="position()"/></xsl:variable>
                    <table  border="{$debug}" cellpadding="0" cellspacing="0" width="100%">
                        <xsl:if test="(./title/text() | ./date/text())">
                            <tr class="position">
                                <xsl:if test="not(name() = 'entry')">
                                    <td valign="baseline" style="width:3%" >
                                        <div class="date">
                                            <xsl:value-of select="./date/text()" />
                                            <xsl:if test="./duration">
                                                (<xsl:value-of select="./duration/text()"/>)
                                            </xsl:if> 
                                        </div>
                                    </td>
                                </xsl:if>
                                <td valign="baseline">
                                    <xsl:choose>
                                        <xsl:when test="not(./title/text() )">&nbsp;</xsl:when>
                                        <xsl:otherwise><h2><xsl:value-of select="./title/text()"/></h2></xsl:otherwise>
                                    </xsl:choose>
                                </td>
                                </tr>
                        </xsl:if>
                        <tr>
                            <td colspan="{$textColspan}">
                                <xsl:for-each select="./text">
                                    <xsl:choose>
                                        <xsl:when test="./@display = 'false'">
                                            <div class="text" style="display:none" id="variable_display_{$parentPosition}_{$position}_{position()}">
                                                <p class="text"><xsl:value-of select="./text()"/></p>
                                            </div>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <div class="text" id="always_display_{$parentPosition}_{$position}_{position()}">
                                                <p class="text"><xsl:value-of select="./text()"/></p>
                                            </div>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:for-each>
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </xsl:template>
    
    <xsl:template name="languages">
        <xsl:for-each select="./resume">
            <a href="javascript:;" onclick="javascript:window.location = '?lang={@lang}';"><xsl:value-of select="@lang"/></a>
            <xsl:if test="position() != last()"><xsl:text> - </xsl:text></xsl:if>
        </xsl:for-each> 
    </xsl:template>
    
    <xsl:template name="options">
        <a href="javascript:;" onclick="javascript:toggleDetails()" >Détails</a> -
        <a href="javascript:;" onclick="javascript:window.print();">Imprimer</a> - 
        <a href="http://www.bouleis.fr">Blog</a> - 
        <a href="javascript:;" onclick="javascript:window.open('cv.xml');">XML</a> -
        <a href="javascript:;" onclick="javascript:window.open('cv.xsl');">XSL</a> -
        <a href="javascript:;" onclick="javascript:window.open('http://validator.w3.org/check?uri=http%3A%2F%2Fwww.bouleis.fr%2Fcv%2F');">Valider HTML</a>
    </xsl:template>
  
    <xsl:template name="style">
        <style type="text/css">

            
            div.text
            {
                margin-left: 0.3cm;
                border-left: 1px solid #557799;
            }
            
            div.section
            {
                margin-top: 0.1cm;
                margin-left: 0.6cm;
            }
            
            div.date
            {
                margin-top : 0.2cm ;
                margin-left: 0.2cm;
                font-size: 10px;
                white-space : nowrap;
                color: #557799;
            }

            
            @media screen {
                body
                {
                    font-family: Arial;
                }
                .maintable
                {
                    width:70%;
                    margin-top: 0.5cm;
                    margin-bottom: 0.5cm;
                    margin-left:auto;
                    margin-right:auto;
                }
                
                table.options
                {
                    font-size:x-small;
                    background-color:#C6DAF0;
                    //text-align:left
                }
                
                div.coords { vertical-align: top; }
                
                div.title
                {
                    text-align: center;
                    font-size: xx-large;
                    margin-right: 0.4cm;
                    margin-left: 0.4cm;
                    margin-top:0.1cm;
                }
                
                div.h1
                {
                    margin-top:0.4cm;
                    background-color:  #457799; 
                }
                
                h1
                {
                    margin-top:0cm;
                    margin-bottom:0cm;
                    margin-left: 0.2cm;
                    font-size: large;
                    color: white;
                    font-variant: small-caps;
                }
                
                h2
                {
                    font-size: medium;
                    padding:0px;
                    margin-top : 0.2cm ;
                    margin-bottom: 0.15cm;
                    margin-left: 0.2cm;
                    text-align: left;
                }
                
               p.text
               {
                   margin-left: 0.1cm;
                   margin-top : 0cm ;
                   margin-bottom: 0cm;
                   text-align: justify;
                   text-indent: 0.5cm;
                }
            }
            
            @media print {
                body
                {
                    font-family: Arial;
                }
                
                .maintable
                {
                    width:100%;
                    margin-top: 0cm;
                    margin-bottom: 0cm;
                    margin-left: 0cm;
                    margin-right: 0cm;
                }
                
                table.options { display:none }
                
                div.coords 
                {
                    vertical-align: top;
                    font-size: 11px;
                }
                
                div.title
                {
                    text-align: center;
                    font-size: 28px;
                    margin-right: 0.4cm;
                    margin-left: 0.4cm;
                    margin-top:0.1cm;
                }
                
                div.h1
                {
                    margin-top:0.4cm;
                    background-color:  #457799; 
                    border-left: 2px solid #557799;
                    border-bottom: 1px solid #557799;
                }
                
                h1
                {
                    font-size: 14px;
                    margin-top:0cm;
                    margin-bottom:0cm;
                    margin-left: 0.2cm;
                    font-variant: small-caps;
                    color: white;
                }
                
                h2
                {
                    font-size: 13px;
                    padding:0px;
                    margin-top : 0.2cm ;
                    margin-bottom: 0.1cm;
                    margin-left: 0.2cm;
                    text-align: left;
                }
                p.text
                {
                    font-size: 11.3px;
                    margin-left: 0.1cm;
                    margin-top : 0cm ;
                    margin-bottom: 0cm;
                    text-align: justify;
                    text-indent: 0.5cm;
                }
            }
        </style>
    </xsl:template>
</xsl:stylesheet>

