<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" />

<xsl:template match="/resume">
  <html>
    <head>
      <title>
        <xsl:value-of select="person/name"/>
        <xsl:for-each select="person/designations/designation">, <xsl:value-of select="."/></xsl:for-each>
      </title>
      <style type="text/css">
body {
   font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
   background-color: white;
   color: black;
}
div.address p {
   margin-bottom: 0;
   margin-top: 0;
   white-space: nowrap;
}
h1, h2 {
   font-variant: small-caps;
   font-weight: bold;
}
h1 {
   text-align: center;
   margin-top: 0;
   margin-bottom: 0;
   font-size: 200%;
}
h2 {
   margin-bottom: 0.25em;
   font-size: 150%;
   border-bottom: 1px solid black;
   border-top: 2px solid black;
}
h3 {
   font-size: 100%;
   margin-bottom: 0.25em;
   margin-top: 0;
}
.header {
   text-align: center;
   padding-bottom: 0.2em;
}
.header p {
   margin-top: 0;
   margin-bottom: 0;
}
table {
   width: 100%;
   margin-top: 0;
}
table td {
   vertical-align: top;
}
td.dates {
   width: 20%;
   height: 1em;
   font-weight: bold;
}
td.address {
   padding-bottom: 0.5em;
}
p {
   margin-top: 0;
   margin-bottom: 0;
}
ul {
   margin-top: 0;
}
a, a:visited {
   color: black;
   text-decoration: none;
}
a:hover {
   text-decoration: underline;
}
table.skills td {
   width: 50%;
}
.skills p {
   text-indent: -2em;
   padding-left: 2em;
}
.publications p+p {
   margin-top: 0.5em;
}
      </style>
    </head>
    <body>
      <div class="header">
        <h1>
          <xsl:value-of select="person/name"/>
          <xsl:for-each select="person/designations/designation">, <xsl:value-of select="."/></xsl:for-each>
        </h1>
        <p>
          <xsl:value-of select="person/address/street" />
          &#8226;
          <xsl:value-of select="person/address/city" />
          <xsl:if test="person/address/province">, <xsl:value-of select="person/address/province" /></xsl:if>
          <xsl:if test="person/address/postalcode">
            &#8226;
            <xsl:value-of select="person/address/postalcode" />
          </xsl:if>
        </p>
        <p>
          <xsl:choose>
            <xsl:when test="person/phone and person/email">
              <xsl:value-of select="person/phone" />
              &#8226;
              <xsl:value-of select="person/email" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="person/phone" />
              <xsl:value-of select="person/email" />
            </xsl:otherwise>
          </xsl:choose>
        </p>
      </div>

      <xsl:if test="summary">
        <h2>Summary</h2>
        <p>
          <xsl:apply-templates select="summary" />
        </p>
      </xsl:if>

      <xsl:if test="objective">
        <h2>Objective</h2>
        <p>
          <xsl:apply-templates select="objective" />
        </p>
      </xsl:if>

      <xsl:if test="education">
        <h2>Education</h2>
        <table class="education">
        <xsl:for-each select="education/item">
          <xsl:apply-templates select="." />
        </xsl:for-each>
        </table>
      </xsl:if>

      <xsl:if test="experience">
        <h2>Work Experience</h2>
        <table class="experience">
        <xsl:for-each select="experience/item">
          <xsl:apply-templates select="." />
        </xsl:for-each>
        </table>
      </xsl:if>

      <xsl:if test="publications">
        <h2>Publications</h2>
        <div class="publications">
        <xsl:for-each select="publications/publication">
          <p><xsl:apply-templates select="." /></p>
        </xsl:for-each>
        </div>
      </xsl:if>

      <xsl:if test="accreditations">
        <h2>Accreditations</h2>
        <table class="accreditations">
        <xsl:for-each select="accreditations/item">
          <xsl:apply-templates select="." />
        </xsl:for-each>
        </table>
      </xsl:if>

      <xsl:if test="awards">
        <h2>Awards &amp; Scholarships</h2>
        <table class="awards">
        <xsl:for-each select="awards/item">
          <xsl:apply-templates select="." />
        </xsl:for-each>
        </table>
      </xsl:if>

      <xsl:if test="volunteer">
        <h2>Volunteer Work</h2>
        <table class="volunteer">
        <xsl:for-each select="volunteer/item">
          <xsl:apply-templates select="." />
        </xsl:for-each>
        </table>
      </xsl:if>

      <xsl:if test="interests">
        <h2>Other Interests</h2>
        <table class="interests">
        <xsl:for-each select="interests/item">
          <xsl:apply-templates select="." />
        </xsl:for-each>
        </table>
      </xsl:if>

      <xsl:if test="skills">
        <h2>Skill Set</h2>
        <table class="skills">
        <tr><td>
        <xsl:for-each select="skills/item[(position() mod 2 = 1)]">
          <p>
            <strong><xsl:value-of select="title" /></strong>:
            <xsl:value-of select="description" />
          </p>
        </xsl:for-each>
        </td>
        <td>
        <xsl:for-each select="skills/item[(position() mod 2 = 0)]">
          <p>
            <strong><xsl:value-of select="title" /></strong>:
            <xsl:value-of select="description" />
          </p>
        </xsl:for-each>
        </td></tr>
        </table>
      </xsl:if>

      <xsl:if test="references">
        <h2>References</h2>
        <xsl:choose>
          <xsl:when test="count(references/item) > 0">
            <table class="volunteer">
              <xsl:for-each select="volunteer/item">
                <xsl:apply-templates select="." />
              </xsl:for-each>
            </table>
          </xsl:when>
          <xsl:otherwise>
            <p>References are available upon request.</p>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </body>
  </html>
</xsl:template>

<xsl:template match="item">
  <tr>
    <td rowspan="2">
      <h3>
      <xsl:choose>
        <xsl:when test="location/url and not(location/name)">
          <a>
            <xsl:attribute name="href"><xsl:value-of select="location/url" /></xsl:attribute>
            <xsl:value-of select="title" />
          </a>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="title" />
        </xsl:otherwise>
      </xsl:choose>
      </h3>
      <xsl:if test="location/name">
        <p>
        <xsl:choose>
          <xsl:when test="location/url">
            <a>
              <xsl:attribute name="href"><xsl:value-of select="location/url" /></xsl:attribute>
              <xsl:value-of select="location/name" />
            </a>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="location/name" />
          </xsl:otherwise>
        </xsl:choose>
        </p>
      </xsl:if>
      <xsl:choose>
        <xsl:when test="description/list">
          <ul>
          <xsl:for-each select="description/list/li">
            <li><xsl:apply-templates select="." /></li>
          </xsl:for-each>
          </ul>
        </xsl:when>
        <xsl:otherwise>
          <p><xsl:apply-templates select="description" /></p>
        </xsl:otherwise>
      </xsl:choose>
    </td>
    <td class="dates">
      <xsl:choose>
        <xsl:when test="date/start">
          <xsl:value-of select="date/start" />
          &#8211;
          <xsl:value-of select="date/end" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="date" />
        </xsl:otherwise>
      </xsl:choose>
    </td>
  </tr>
  <tr>
    <td class="address">
      <xsl:apply-templates select="location/address" />
    </td>
  </tr>
</xsl:template>

<xsl:template match="address">
  <div class="address">
    <p class="street"><xsl:value-of select="street" /></p>
    <p class="city">
      <xsl:value-of select="city" />
      <xsl:if test="province">, <xsl:value-of select="province" /></xsl:if>
    </p>
    <p class="postalcode"><xsl:value-of select="postalcode" /></p>
  </div>
</xsl:template>

<xsl:template match="b">
  <b><xsl:apply-templates select="*|text()"/></b>
</xsl:template>

<xsl:template match="i">
  <i><xsl:apply-templates select="*|text()"/></i>
</xsl:template>

</xsl:stylesheet>

