<!-- DWXMLSource="graduates.xml" --> 
<!-- Begin XSLT Stylesheet --> 
<xsl:stylesheet  
  version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
  <xsl:strip-space elements="*"/>
  <xsl:preserve-space elements="brief-summary"/>
  
  <!-- This "template" runs on the data in the root <news> element --> 
  <xsl:template match="/">
  
  <!-- USED FOR TESTING 	
	
	<style type="text/css">
		.page6-color { color: #993333; }
		.page6-title-small {font-family:Arial, sans-serif; font-size: 16px; font-weight:bold;}
		.page6-title-big {font-family:Georgia, serif; font-size: 36px; font-weight:bold;}	
		.page6-map-icon {float: left; margin: 5px;}
		.page6-grad-school {margin: 25px; font-family: Arial, sans-serif; font-size:14px; }
		.page6-grad-job {font-family: Arial, sans-serif; font-size:14px;}
		.page6-grad-name {font-family: Arial, sans-serif; font-size:14px; font-weight:bold;}		
		#page6 { width: 800px; margin: auto; }
		#page6-header { margin: auto; text-align:center;}
		#page6-footer { margin: auto; text-align:right;}
    </style>
	
   -->
   
    	<xsl:apply-templates />
    </xsl:template>
    
    <xsl:template match="markers">
      <xsl:apply-templates select="marker" />
    </xsl:template>
    
    <!-- For each news item -->
    <xsl:template match="marker">
      <div style="position: relative; margin-top: 5px; height: 100px;">
         <xsl:apply-templates select="person"/>
         <br />
         <xsl:apply-templates select="school"/>
      </div>
    </xsl:template>
    
    <!-- the person block -->
    <xsl:template match="person">
      <div class="page6-map-icon">
         <xsl:apply-templates select="thumb"/>
      </div>
      <xsl:apply-templates select="name"/>
      <xsl:apply-templates select="title"/>
    </xsl:template>
      
    <!-- For each image in this person create an image tag -->
    <xsl:template match="thumb">
      <xsl:variable name="marker-count" select='count(../../preceding-sibling::*)+1' />
      <xsl:variable name="marker" select='count(../../preceding-sibling::*)' />
      <div style="border: 1px black solid; margin-right: 5px; background-image:url({text()}); height: 86px; width: 86px;">
      <img onclick="doEvent({$marker}, 'click')" 
           ondblclick="doEvent({$marker}, 'dblclick')" style="border: none; margin-top: -10px; margin-left: -10px;">   
         <xsl:attribute name="src">images/<xsl:value-of select="$marker-count"/>.png</xsl:attribute>
         <xsl:attribute name="alt"><xsl:value-of select="../name"/></xsl:attribute>         
      </img>
      </div>
    </xsl:template>
   
    <!-- the title block -->
    <xsl:template match="name">
      <xsl:variable name="name-link">
        <xsl:call-template name="linktify">
          <xsl:with-param name="title" select="text()"/>
          <xsl:with-param name="link" select="../url/text()"/>
        </xsl:call-template>
      </xsl:variable>
      <span class="page6-grad-name">
        <xsl:value-of select="$name-link" disable-output-escaping="yes"/>
      </span>
      <xsl:text>, </xsl:text>
    </xsl:template>
   
    <!-- the summary block -->
    <xsl:template match="title">
      <span class="page6-grad-job">
        <xsl:call-template name="create-title-link">
          <xsl:with-param name="title" select="@name"/>
          <xsl:with-param name="links" select=".//title-link"/>
        </xsl:call-template>
      </span>
    </xsl:template>
    
    <xsl:template name="create-title-link">
      <xsl:param name="title"/>
      <xsl:param name="links"/>
      <xsl:param name="index" select="1"/>

      <xsl:choose>
        <xsl:when test="$index > count($links)">
          <!--finished looking-->
          <xsl:value-of select="$title" disable-output-escaping="yes"/>
        </xsl:when>
        <xsl:otherwise>
          <!--this isn't any longer-->
          <xsl:variable name="title-with-link">
            <xsl:call-template name="linktify">
              <xsl:with-param name="title" select="$title"/>
              <xsl:with-param name="name" select="$links[$index]/@name"/>
              <xsl:with-param name="link" select="$links[$index]/@url"/>              
            </xsl:call-template>
          </xsl:variable>
          <xsl:call-template name="create-title-link">
            <xsl:with-param name="title" select="$title-with-link"/>
            <xsl:with-param name="links" select="$links"/>
            <xsl:with-param name="index" select="$index + 1"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
    
    <xsl:template name="linktify">
      <xsl:param name="title" select="'title-link:undefined'"/>
      <xsl:param name="name" select="$title"/>
      <xsl:param name="link" select="'title-link:undefined'"/>
      
      <xsl:variable name="url-string">
        &lt;a href=&quot;<xsl:value-of select="$link"/>&quot;&gt;<xsl:value-of select="$name"/>&lt;/a&gt;
      </xsl:variable>
      
      <xsl:variable name="new-title">
        <xsl:call-template name="string-replace-all">
          <xsl:with-param name="text" select="$title"/>
          <xsl:with-param name="replace" select="$name"/>
          <xsl:with-param name="by" select="$url-string"/>
        </xsl:call-template>
      </xsl:variable>
      
      <xsl:value-of select="$new-title"/>
    </xsl:template>
        
    <xsl:template name="string-replace-all">
      <xsl:param name="text" />
      <xsl:param name="replace" />
      <xsl:param name="by" />
      <xsl:choose>
        <xsl:when test="contains($text, $replace)">
          <xsl:value-of select="substring-before($text,$replace)" />
          <xsl:value-of select="$by" />
          <xsl:call-template name="string-replace-all">
            <xsl:with-param name="text" select="substring-after($text,$replace)" />
            <xsl:with-param name="replace" select="$replace" />
            <xsl:with-param name="by" select="$by" />
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$text" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
    
    <!-- links that open in a new window -->
    <xsl:template match="school">
      <xsl:variable name="school-link">
        <xsl:call-template name="linktify">
          <xsl:with-param name="title" select="@name"/>
          <xsl:with-param name="link" select="@url"/>
        </xsl:call-template>
      </xsl:variable>
      <span class="page6-grad-school">
         <xsl:value-of select="$school-link" disable-output-escaping="yes"/>
      </span>
    </xsl:template>
    
 </xsl:stylesheet>
