<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:output method="xml" 
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
    indent="yes"/>


  <!--
    -  Commonly-used variables.
    -->
  <xsl:variable name="SPACE" select="' '" />
  <xsl:variable name="SEPARATOR" select="' :: '" />
  <xsl:variable name="SUMMARY_SKILL_SEPARATOR" select="' - '" />
  <xsl:variable name="DEFAULT_LIST_SEPARATOR" select="';'" />


  <!--
    -  Main template.
    -->
  <xsl:template match="/">
    <html>
      <head>
	<title>
          <xsl:value-of select="/resume/@name" />'s Resume
	</title>
        <link type="text/css" rel="stylesheet" href="resume.css" />
      </head>
      <body>
        <xsl:apply-templates select="/resume" />
        <xsl:call-template name="resume_footer" />
      </body>
    </html>
  </xsl:template>


  <!--
    -  Template for resume.
    -->
  <xsl:template match="/resume">
    <div class="resume">
      <div class="resume-header">
        <div class="resume-name">
          <xsl:value-of select="@name" />
        </div>
        <xsl:apply-templates select="contact" />
      </div>
      <div class="resume-body">
        <xsl:apply-templates select="summary" />
        <xsl:apply-templates select="experience" />
        <xsl:apply-templates select="education" />
        <xsl:apply-templates select="personal" />
      </div>
    </div>
  </xsl:template>


  <!--
    -  Template for resume contact.
    -->
  <xsl:template match="/resume/contact">
    <div class="resume-contact">
      <xsl:value-of select="address/street" />
      <xsl:value-of select="$SEPARATOR" />
      <xsl:value-of select="address/city" />,
      <xsl:value-of select="address/state" />
      <xsl:value-of select="$SPACE" />
      <xsl:value-of select="address/zip" />
      <xsl:value-of select="$SEPARATOR" />
      <xsl:value-of select="phone/@number" />
      <xsl:value-of select="$SEPARATOR" />
      <a href="mailto:{email/@addr}">
        <xsl:value-of select="email/@addr" />
      </a>
      <xsl:value-of select="$SEPARATOR" />
      <a href="http://{web/@url}">
        <xsl:value-of select="web/@url" />
      </a>
    </div>
  </xsl:template>


  <!--
    -  Template for Summary section.
    -->
  <xsl:template match="/resume/summary">
    <div class="summary">
      <!-- Summary section title. -->
      <div class="section-title">Summary</div>
      <!-- Summary. -->
      <div class="summary-desc">
        <xsl:apply-templates select="desc" />
        Skills include:
      </div>
      <!-- Skills. -->
      <div class="summary-skills">
        <ul class="summary-skills-list">
          <xsl:apply-templates select="skills/skill" />
        </ul>
      </div>
    </div>
  </xsl:template>


  <!--
    -  Template for skills in Summary section.
    -->
  <xsl:template match="/resume/summary/skills/skill">
    <li class="summary-skill">
      <span class="summary-skill-category">
        <xsl:value-of select="@category" />
      </span>
      <span class="summary-skill-separator">
        <xsl:value-of select="$SUMMARY_SKILL_SEPARATOR" />
      </span>
      <span class="summary-skill-desc">
        <xsl:value-of select="." />
      </span>
    </li>
  </xsl:template>


  <!--
    -  Template for Experience section.
    -->
  <xsl:template match="/resume/experience">
    <div class="experience">
      <div class="section-title">Experience</div>
      <xsl:apply-templates select="company" />
    </div>
  </xsl:template>


  <!--
    -  Template for companies in Experience section.
    -->
  <xsl:template match="/resume/experience/company">
    <div class="company">
      <!-- Company name. -->
      <span class="company-name">
        <xsl:choose>
          <xsl:when test="@url">
            <a href="http://{@url}" target="_blank">
              <xsl:value-of select="@name" />
            </a>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@name" />
          </xsl:otherwise>
        </xsl:choose>
      </span>
      <!-- Company location. -->
      <span class="company-location">
        (<xsl:value-of select="@location" />)
      </span>
      <!-- Company start and end dates. -->
      <span class="company-dates">
        <xsl:value-of select="@start" />
        ~
        <xsl:value-of select="@end" />
      </span>
    </div>
    <!-- Company description. -->
    <div class="company-desc">
      <xsl:apply-templates select="desc" />
    </div>
    <!-- Accomplishments at company. -->
    <xsl:if test="accomplishments">
      <div class="company-accomplishments">
        <ul class="company-accomplishments-list">
          <xsl:apply-templates select="accomplishments/accomplishment" />
        </ul>
      </div>
    </xsl:if>
  </xsl:template>


  <!--
    -  Template for accomplishments at companies in Experience section.
    -->
  <xsl:template match="/resume/experience/company/accomplishments/accomplishment">
    <li class="company-accomplishment">
      <xsl:if test="project">
        <div class="company-accomplishment-project">
          <span class="company-accomplishment-project-name">
            <xsl:choose>
              <xsl:when test="project/@url">
                <a href="http://{project/@url}" target="_blank">
                  <xsl:value-of select="project/@name" />
                </a>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="project/@name" />
              </xsl:otherwise>
            </xsl:choose>
          </span>
          <span class="company-accomplishment-project-location">
            (<xsl:value-of select="project/@location" />)
          </span>
        </div>
      </xsl:if>
      <xsl:apply-templates select="desc" />
    </li>
  </xsl:template>


  <!--
    -  Template for Education section.
    -->
  <xsl:template match="/resume/education">
    <div class="education">
      <div class="section-title">Education</div>
      <xsl:apply-templates select="institution" />
    </div>
  </xsl:template>


  <!--
    -  Template for institutions in Education section.
    -->
  <xsl:template match="/resume/education/institution">
    <div class="institution">
      <span class="institution-name">
        <xsl:choose>
          <xsl:when test="@url">
            <a href="http://{@url}" target="_blank">
              <xsl:value-of select="@name" />
            </a>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="@name" />
          </xsl:otherwise>
        </xsl:choose>
      </span>
      <span class="institution-location">
        (<xsl:value-of select="@location" />)
      </span>
    </div>
    <xsl:if test="desc">
      <div class="institution-desc">
        <xsl:apply-templates select="desc" />
        <!-- !FIX - Fix the coursework logic and flow. -->
        <span class="institution-coursework">
          <xsl:apply-templates select="coursework/course" />
        </span>
      </div>
    </xsl:if>
    <xsl:if test="school">
      <div class="institution-schools">
        <ul class="institution-schools-list">
          <xsl:apply-templates select="school" />
        </ul>
      </div>
    </xsl:if>
  </xsl:template>


  <!--
    -  Template for schools within an institution.
    -->
  <xsl:template match="/resume/education/institution/school">
    <li class="institution-school">
      <div class="institution-school-desc">
        <xsl:apply-templates select="desc" />
      </div>
      <!-- !FIX - Fix the coursework logic and flow. -->
      <div class="institution-school-coursework">
        <xsl:value-of select="coursework/label" />:
        <xsl:apply-templates select="coursework/course" />
      </div>
    </li>
  </xsl:template>


  <!--
    -  Template for courses.
    -->
  <xsl:template match="/resume/education/institution//coursework/course">
    <xsl:value-of select="." />
    <xsl:choose>
      <xsl:when test="position() = last()">.</xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="concat( $DEFAULT_LIST_SEPARATOR, $SPACE )" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <!--
    -  Template for Personal section.
    -->
  <xsl:template match="/resume/personal">
    <div class="personal">
      <div class="section-title">Personal</div>
      <xsl:apply-templates select="category" />
    </div>
  </xsl:template>


  <!--
    -  Template for categories in Personal section.
    -->
  <xsl:template match="/resume/personal/category">
    <div class="personal-category">
      <span class="personal-category-name">
        <xsl:value-of select="@name" />:
      </span>
      <span class="personal-category-items">
        <xsl:apply-templates select="item" />
      </span>
    </div>
  </xsl:template>


  <!--
    -  Template for category items in Personal section.
    -->
  <xsl:template match="/resume/personal/category/item">
    <!-- Handle the item. -->
    <xsl:value-of select="." />
    <xsl:choose>
      <xsl:when test="position() = last()">.</xsl:when>
      <xsl:otherwise>
        <!-- Determine the separator for this item's category. -->
        <xsl:choose>
          <xsl:when test="../@separator">
            <xsl:value-of select="concat( ../@separator, $SPACE )" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat( $DEFAULT_LIST_SEPARATOR, $SPACE )" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <!--
    -  Template for descriptions in all the sections.
    -->
  <xsl:template match="desc">
    <xsl:apply-templates select="node()" />
  </xsl:template>


  <!--
    -  Template for the text content within descriptions.
    -->
  <xsl:template match="desc/text()">
    <xsl:value-of select="." />
  </xsl:template>


  <!--
    -  Template for job titles within descriptions.
    -->
  <xsl:template match="desc/job_title">
    <span class="job-title">
      <xsl:value-of select="." />
    </span>
  </xsl:template>


  <!--
    -  Template for degrees within descriptions.
    -->
  <xsl:template match="desc/degree">
    <span class="degree">
      <xsl:value-of select="." />
    </span>
  </xsl:template>


  <!--
    -  Named template for the footer.
    -->
  <xsl:template name="resume_footer">
    <div class="resume-footer">
      <hr />
      <div>
        Last updated:  2003/09/19
        ::
        Generated using
        <a href="http://xml.apache.org/xalan-j/" target="_blank">Apache
          Xalan</a>
        ::
        Source:
        <a href="Alex_Chou_resume.xml">XML</a>
        |
        <a href="resume_html.xsl">XSLT</a>
        ::
        <a href="http://validator.w3.org/check/referer" target="_blank">Valid
          XHTML document</a>
      </div>
    </div>
  </xsl:template>

</xsl:stylesheet>
