<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:europass="http://europass.cedefop.europa.eu/Europass/V1.0">
    <xsl:template match="//europass:learnerinfo">
        <learnerinformation xmlns="http://www.imsglobal.org/xsd/imslip_v1p0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" xsi:schemaLocation="http://www.imsglobal.org/xsd/imslip_v1p0 http://www.imsglobal.org/xsd/imslip_v1p0.xsd">

            <xsl:element name="comment">
                <xsl:value-of select="misclist/misc[@type='additional']/text()"/>
            </xsl:element>
            
            <contentype>
                    <xsl:element name="comment">
                    <xsl:value-of select="docinfo/comment/text()"/> - Produce with xslt from EIfEL
                </xsl:element>
                <referential/>
            </contentype>
                    
            <identification>
            <name>
                <partname>
                    <typename>
                        <tysource sourcetype="imsdefault"/>
                        <tyvalue>First</tyvalue>
                    </typename>
                    <text>
                        <xsl:value-of select="identification/firstname/text()"/>    
                    </text>
                </partname>
                <partname>
                    <typename>
                        <tysource sourcetype="imsdefault"/>
                        <tyvalue>Last</tyvalue>
                    </typename>
                    <text>
                        <xsl:value-of select="identification/lastname/text()"/>
                    </text>
                </partname>
                </name>
                <address>
                    <street>
                        <streetname>
                            <xsl:value-of select="identification/contactinfo/address/text()"/>     
                        </streetname>
                    </street>                  
                </address>
                <contactinfo>
                    <telephone>
                            <areacode>
                            </areacode>
                            <indnumber>
                            <xsl:value-of select="identification/contactinfo/telephone/text()"/>     
                        </indnumber>
                    </telephone>
                </contactinfo>
                <contactinfo>
                    <facsimile>
                        <areacode>
                        </areacode>
                        <indnumber>
                            <xsl:value-of select="identification/contactinfo/fax/text()"/>     
                        </indnumber>
                    </facsimile>
                </contactinfo>
                <contactinfo>
                    <mobile>
                        <areacode>
                        </areacode>
                        <indnumber>
                            <xsl:value-of select="identification/contactinfo/mobile/text()"/>     
                        </indnumber>
                    </mobile>
                </contactinfo>
                <contactinfo>
                    <email>
                        <xsl:value-of select="identification/contactinfo/email/text()"/>     
                    </email>
                </contactinfo>
                <demographics>
                    <xsl:if test="identification/demographics/gender/text()!=''">
                    <xsl:element name="gender">
                        <xsl:attribute name="gender">
                                <xsl:value-of select="identification/demographics/gender/text()"/>
                            </xsl:attribute>
                        </xsl:element>
                     </xsl:if>
                        <date>
                        <typename>
                            <tysource sourcetype="imsdefault"/>
                            <tyvalue>Birth</tyvalue>
                        </typename>
                        <datetime>
                            <xsl:value-of select="identification/demographics/birthdate/text()"/>T00:00:00
                        </datetime>
                    </date>
                    <placeofbirth>
                        <xsl:value-of select="identification/demographics/nationality/text()"/>
                    </placeofbirth>
                </demographics>
            </identification>
            
            <goal>
                <comment xml:lang="en">Desired employment / Occupational field</comment>
                <description>
                    <short>
                        <xsl:value-of select="application/text()"/>     
                    </short>
                </description>
            </goal>

            <activity>
                <comment xml:lang="en">work experience</comment>
                <contentype>
                    <referential>
                        <indexid>work1</indexid>
                    </referential>
                </contentype>
                <date>
                    <typename>
                        <tysource sourcetype="imsdefault"/>
                        <tyvalue>finish</tyvalue>
                    </typename>
                    <datetime>
                        <xsl:value-of select="workexperiencelist/workexperience/period/to/year/text()"/>     
                        <xsl:value-of select="substring(workexperiencelist/workexperience/period/to/month/text(),2)"/>     
                        <xsl:value-of select="substring(workexperiencelist/workexperience/period/to/day/text(),3)"/>T00:00:00     
                    </datetime>
                </date>
                <date>
                    <typename>
                        <tysource sourcetype="imsdefault"/>
                        <tyvalue>start</tyvalue>
                    </typename>
                    <datetime>
                        <xsl:value-of select="workexperiencelist/workexperience/period/from/year/text()"/>     
                        <xsl:value-of select="substring(workexperiencelist/workexperience/period/from/month/text(),2)"/>     
                        <xsl:value-of select="substring(workexperiencelist/workexperience/period/from/day/text(),3)"/>T00:00:00     
                    </datetime>
                </date>
                <definition>
                    <comment xml:lang="en">Main activities and responsibilities</comment>
                    <description>
                        <short>

                        </short>
                    </description>
                </definition>
            </activity>

            <affiliation>
                <comment xml:lang="en">work experience</comment>
                <contentype>
                    <referential>
                        <indexid>affiliation1</indexid>
                    </referential>
                </contentype>
                <classification>
                    <xsl:value-of select="workexperiencelist/workexperience/sector/text()"/>     
                </classification>
                <role>
                    <comment xml:lang="en">Occupation or position held</comment>
                    <description>
                        <short>
                            <xsl:value-of select="workexperiencelist/workexperience/position/text()"/>     
                        </short>
                    </description>
                </role>
                <organization>
                    <description>
                        <short>
                            <xsl:value-of select="workexperiencelist/workexperience/employer/text()"/>     
                        </short>
                    </description>
                </organization>
            </affiliation>

            <relationship>
                <tuple>
                    <tuplesource>
                        <indexid>work1</indexid>
                    </tuplesource>
                    <tuplerelation>
                        <typename>
                            <tysource sourcetype="imsdefault"/>
                            <tyvalue>ispartof</tyvalue>
                        </typename>
                        <text>ispartof</text>
                    </tuplerelation>
                    <tupledest>
                        <indexid>affiliation1</indexid>
                    </tupledest>
                </tuple>
            </relationship>
               
            <xsl:for-each select="educationlist/education">
                <qcl>
                <comment xml:lang="en">Education and training</comment>
                <title>
                    <xsl:value-of select="title/text()"/>     
                </title>
                <organization>
                    <description>
                        <short>
                            <xsl:value-of select="organisation/text()"/>     
                        </short>
                    </description>
                </organization>
                <level>
                    <text>
                        <xsl:value-of select="level/text()"/>     
                    </text>
                </level>
                <date>
                    <typename>
                        <tysource sourcetype="imsdefault"/>
                        <tyvalue>finish</tyvalue>
                    </typename>
                    <datetime>
                        <xsl:value-of select="period/to/year/text()"/>     
                        <xsl:value-of select="substring(period/to/month/text(),2)"/>     
                        <xsl:value-of select="substring(period/to/day/text(),3)"/>T00:00:00     
                    </datetime>
                </date>
                <date>
                    <typename>
                        <tysource sourcetype="imsdefault"/>
                        <tyvalue>start</tyvalue>
                    </typename>
                    <datetime>
                        <xsl:value-of select="period/from/year/text()"/>     
                        <xsl:value-of select="substring(period/from/month/text(),2)"/>     
                        <xsl:value-of select="substring(period/from/day/text(),3)"/>T00:00:00    
                    </datetime>
                </date>
            </qcl>
          </xsl:for-each>
                    

            <competency>
                        <contentype>
                            <referential>
                                <sourcedid>
                                    <source>Europass-CV-Skills</source>
                                    <id>http://profiles.eife-l.org/europass/Europass-Skills-Social.xml</id>
                                </sourcedid>
                            </referential>
                        </contentype>
                        <description>
                            <short>social</short>
                            <long>
                                <xsl:value-of select="skilllist/skill[@type='social']/text()"/>
                            </long>
                        </description>
                    </competency>

            <competency>
                        <contentype>
                            <referential>
                                <sourcedid>
                                    <source>Europass-CV-Skills</source>
                                    <id>http://profiles.eife-l.org/europass/Europass-Skills-Organisational.xml</id>
                                </sourcedid>
                            </referential>
                        </contentype>
                        <description>
                            <short>organisational</short>
                            <long>
                                <xsl:value-of select="skilllist/skill[@type='organisational']/text()"/>
                            </long>
                        </description>
                    </competency>

            <competency>
                        <contentype>
                            <referential>
                                <sourcedid>
                                    <source>Europass-CV-Skills</source>
                                    <id>http://profiles.eife-l.org/europass/Europass-Skills-Technical.xml</id>
                                </sourcedid>
                            </referential>
                        </contentype>
                        <description>
                            <short>technical</short>
                            <long>
                                <xsl:value-of select="skilllist/skill[@type='technical']/text()"/>
                            </long>
                        </description>
                    </competency>

            <competency>
                        <contentype>
                            <referential>
                                <sourcedid>
                                    <source>Europass-CV-Skills</source>
                                    <id>http://profiles.eife-l.org/europass/Europass-Skills-Computer.xml</id>
                                </sourcedid>
                            </referential>
                        </contentype>
                        <description>
                            <short>computer</short>
                            <long>
                                <xsl:value-of select="skilllist/skill[@type='computer']/text()"/>
                            </long>
                        </description>
                    </competency>

            <competency>
                        <contentype>
                            <referential>
                                <sourcedid>
                                    <source>Europass-CV-Skills</source>
                                    <id>http://profiles.eife-l.org/europass/Europass-Skills-Artistic.xml</id>
                                </sourcedid>
                            </referential>
                        </contentype>
                        <description>
                            <short>artistic</short>
                            <long>
                                <xsl:value-of select="skilllist/skill[@type='artistic']/text()"/>
                            </long>
                        </description>
                    </competency>

            <competency>
                        <contentype>
                            <referential>
                                <sourcedid>
                                    <source>Europass-CV-Skills</source>
                                    <id>http://profiles.eife-l.org/europass/Europass-Skills-Driving.xml</id>
                                </sourcedid>
                            </referential>
                        </contentype>
                        <description>
                            <short>driving</short>
                            <long>
                                <xsl:value-of select="skilllist/skill[@type='driving']/text()"/>
                            </long>
                        </description>
                    </competency>

            <competency>
                <contentype>
                    <referential>
                        <sourcedid>
                            <source>Europass-CV-Skills</source>
                            <id>http://profiles.eife-l.org/europass/Europass-Skills-Other.xml</id>
                        </sourcedid>
                    </referential>
                </contentype>
                <description>
                            <short>other</short>
                            <long>
                                <xsl:value-of select="skilllist/skill[@type='other']/text()"/>
                            </long>
                        </description>
                    </competency>

            <accessibility>
                <comment xml:lang="en">Language(s)</comment>
                <language>
                    <typename>
                        <tyvalue>
                            <xsl:value-of select="languagelist/language[@type='mother']/name/text()"/>
                        </tyvalue>
                    </typename>
                    <comment xml:lang="en">Mother tongue(s)</comment>
                </language>
                <language>
                    <typename>
                        <tyvalue>
                            <xsl:value-of select="languagelist/language[@type='foreign']/name/text()"/>
                        </tyvalue>
                    </typename>
                    <comment xml:lang="en">Other language(s)</comment>
                    <proficiency profmode="Write">
                        <xsl:value-of select="languagelist/language[@type='foreign']/level/writing/text()"/>
                    </proficiency>
                    <proficiency profmode="Read">
                        <xsl:value-of select="languagelist/language[@type='foreign']/level/reading/text()"/>
                    </proficiency>
                    <proficiency profmode="OralSpeak">
                        <xsl:value-of select="languagelist/language[@type='foreign']/level/spokeninteraction/text()"/>
                    </proficiency>
                    <proficiency profmode="OralComp">
                        <xsl:value-of select="languagelist/language[@type='foreign']/level/listening/text()"/>
                    </proficiency>
                </language>
            </accessibility>

            <transcript>
                <exrefrecord>
                    <recformat uri="" />
                    <recdata uri="" />
                    <description>
                        <short>
                        <xsl:value-of select="misclist/misc[@type='annexes']/text()"/>
                        </short>
                    </description>
                </exrefrecord>
            </transcript>
            
        </learnerinformation>
    </xsl:template>
</xsl:stylesheet>