<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:date="http://exslt.org/dates-and-times" > 
<xsl:include href="http://www.barrycornelius.com/runningstatic/xsl/url-encode.xsl" />
<xsl:output method="html" indent="no" encoding="ISO-8859-1"/>

<xsl:template name="rnod">
   <xsl:param name="pdate" />
   <xsl:variable name="dd" select="substring($pdate,7,2) - 1"/>
   <xsl:variable name="mm" select="substring($pdate,5,2) - 1"/>
   <xsl:variable name="ccyy" select="substring($pdate,1,4)"/>
   <xsl:value-of select="$ccyy*31*12 + $mm*31 + $dd"/>
</xsl:template>

<xsl:template name="output_time">
   <xsl:param name="time" />
   <xsl:value-of select="substring($time,1,2)*60+substring($time,4,2)"/>
   <xsl:text>m</xsl:text>
   <xsl:value-of select="substring($time,7,2)"/>
   <xsl:text>s</xsl:text>
</xsl:template>

<xsl:template name="output_url">
   <xsl:param name="url" />
   <xsl:param name="label" />
<xsl:choose>
   <xsl:when test="$url='-'">
      <xsl:text>-</xsl:text>
   </xsl:when>
   <xsl:otherwise>
   <a>
      <xsl:attribute name="href">
      <xsl:choose>
         <xsl:when test="$url='ME'">
            <xsl:text>../extras/formme.htm</xsl:text>
         </xsl:when>
         <xsl:when test="$url='SE'">
            <xsl:text>../extras/formse.htm</xsl:text>
         </xsl:when>
         <xsl:when test="starts-with($url, 'https://')">
            <xsl:value-of select="$url"/>
         </xsl:when>
         <xsl:when test="starts-with($url, 'http://')">
            <xsl:value-of select="$url"/>
         </xsl:when>
         <xsl:when test="starts-with($url, 'mailto://')">
            <xsl:value-of select="$url"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>http://</xsl:text><xsl:value-of select="$url"/>
         </xsl:otherwise>
      </xsl:choose>
      </xsl:attribute>
      <xsl:value-of select="$label"/>
   </a>
   </xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="output_pr">
   <xsl:choose>
   <xsl:when test="prevrace='-'">
      <xsl:text>-</xsl:text>
   </xsl:when>
   <xsl:otherwise>
      <a>
         <xsl:attribute name="href">
            <xsl:variable name="pr" select="substring(prevrace,1,1)"/>
            <xsl:choose>
               <xsl:when test="$pr='P'">
               <xsl:text>prev.htm#</xsl:text>
               </xsl:when>
               <xsl:when test="$pr='R'">
               <xsl:text>rest.htm#</xsl:text>
               </xsl:when>
            </xsl:choose>
            <xsl:variable name="label" select="substring(prevrace,2)"/>
            <xsl:value-of select="$label"/>
         </xsl:attribute>
         <xsl:text>lastyear</xsl:text>
      </a>
   </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="output_forumid">
   <xsl:choose>
      <xsl:when test="forumid='-'">
         <xsl:text>-</xsl:text>
      </xsl:when>
      <xsl:otherwise>
         <a>
            <xsl:attribute name="href">
               <xsl:text>/forum/index.php?msg=</xsl:text>
               <xsl:value-of select="forumid"/>
            </xsl:attribute>
            <xsl:text>chat</xsl:text>
         </a>
         <xsl:text>:</xsl:text>
         <xsl:value-of select="forumkids"/>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="output_smap">
   <xsl:param name="url" />
<xsl:choose>
   <xsl:when test="$url='-'">
      <xsl:text>-</xsl:text>
   </xsl:when>
   <xsl:when test="starts-with($url,'x') or starts-with($url,'X')">
      <xsl:variable name="x" select="substring($url,  3, 6)"/>
      <xsl:variable name="y" select="substring($url, 12, 6)"/>
      <xsl:variable name="z" select="substring($url, 21, 1)"/>
      <a>
         <xsl:attribute name="href">
            <xsl:text>http://www.streetmap.co.uk/newmap.srf?x=</xsl:text>
            <xsl:value-of select="$x"/>
            <xsl:text>&amp;y=</xsl:text>
            <xsl:value-of select="$y"/>
            <xsl:text>&amp;z=</xsl:text>
            <xsl:value-of select="$z"/>
            <xsl:text>&amp;sv=</xsl:text>
            <xsl:value-of select="$x"/>
            <xsl:text>,</xsl:text>
            <xsl:value-of select="$y"/>
<!--
            <xsl:text>&amp;st=4&amp;ar=N&amp;dn=</xsl:text>
            <xsl:value-of select="$dn"/>
-->
            <xsl:text>&amp;st=4&amp;ar=N</xsl:text>
         </xsl:attribute>
         <xsl:text>s-map</xsl:text>
      </a>
   </xsl:when>
   <xsl:otherwise>
      <xsl:call-template name="output_url">
         <xsl:with-param name="url" select="$url"/>
         <xsl:with-param name="label">s-map</xsl:with-param>
      </xsl:call-template>
   </xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="races">
   <xsl:choose>
      <xsl:when test="$version='nextrdf'">
         <rdf:RDF 
	    xmlns:purl="http://purl.org/rss/1.0/"
            xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
            <xsl:text>
</xsl:text>
            <purl:channel 
   	    rdf:about="http://www.barrycornelius.com/running/races/next.rdf">
               <xsl:text>
</xsl:text>
               <purl:title>Future races in North East England</purl:title>
               <xsl:text>
</xsl:text>
               <purl:description>Future races in North East England</purl:description>
               <xsl:text>
</xsl:text>
   	    <purl:link>http://www.barrycornelius.com/running/races/next.htm</purl:link>
               <xsl:text>
</xsl:text>
   	    <purl:image rdf:resource="http://www.barrycornelius.com/style/favicon.ico"/>
               <xsl:text>
</xsl:text>
   	    <purl:items>
               <xsl:text>
</xsl:text>
   	       <rdf:Seq>
               <xsl:text>
</xsl:text>
                     <xsl:apply-templates 
                           select="race[translate(mydate,'-','')>translate($today,'-','')
	               and area='ne']"
            	       mode="rdfchannel">
                        <xsl:sort order="descending" select="mymodified"/>
                        <xsl:sort order="ascending" select="location"/>
                     </xsl:apply-templates>
   	       </rdf:Seq>
               <xsl:text>
</xsl:text>
   	    </purl:items>
               <xsl:text>
</xsl:text>
            </purl:channel>
            <xsl:text>
</xsl:text>
            <purl:image rdf:about="http://www.barrycornelius.com/style/favicon.ico">
               <xsl:text>
</xsl:text>
               <purl:title>Future races in North East England</purl:title>
               <xsl:text>
</xsl:text>
               <purl:url>http://www.barrycornelius.com/style/favicon.ico</purl:url>
               <xsl:text>
</xsl:text>
   	       <purl:link>http://www.barrycornelius.com/running/races/next.htm</purl:link>
               <xsl:text>
</xsl:text>
            </purl:image>
            <xsl:text>
</xsl:text>
            <xsl:apply-templates 
                  select="race[translate(mydate,'-','')>translate($today,'-','')
   	       and area='ne']"
   	       mode="rdfitem">
               <xsl:sort order="descending" select="mymodified"/>
               <xsl:sort order="ascending" select="location"/>
            </xsl:apply-templates>
         </rdf:RDF>
      </xsl:when>
      <xsl:when test="$version='oxnextrdf'">
         <rdf:RDF 
	    xmlns:purl="http://purl.org/rss/1.0/"
            xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
            <xsl:text>
</xsl:text>
            <purl:channel 
   	    rdf:about="http://www.barrycornelius.com/running/races/oxnext.rdf">
               <xsl:text>
</xsl:text>
               <purl:title>Future races near Oxford</purl:title>
               <xsl:text>
</xsl:text>
               <purl:description>Future races near Oxford</purl:description>
               <xsl:text>
</xsl:text>
   	    <purl:link>http://www.barrycornelius.com/running/races/oxnext.htm</purl:link>
               <xsl:text>
</xsl:text>
   	    <purl:image rdf:resource="http://www.barrycornelius.com/style/favicon.ico"/>
               <xsl:text>
</xsl:text>
   	    <purl:items>
               <xsl:text>
</xsl:text>
   	       <rdf:Seq>
               <xsl:text>
</xsl:text>
                     <xsl:apply-templates 
                           select="race[translate(mydate,'-','')>translate($today,'-','')
	               and area='ox']"
            	       mode="rdfchannel">
                        <xsl:sort order="descending" select="mymodified"/>
                        <xsl:sort order="ascending" select="location"/>
                     </xsl:apply-templates>
   	       </rdf:Seq>
               <xsl:text>
</xsl:text>
   	    </purl:items>
               <xsl:text>
</xsl:text>
            </purl:channel>
            <xsl:text>
</xsl:text>
            <purl:image rdf:about="http://www.barrycornelius.com/style/favicon.ico">
               <xsl:text>
</xsl:text>
               <purl:title>Future races near Oxford</purl:title>
               <xsl:text>
</xsl:text>
               <purl:url>http://www.barrycornelius.com/style/favicon.ico</purl:url>
               <xsl:text>
</xsl:text>
   	       <purl:link>http://www.barrycornelius.com/running/races/oxnext.htm</purl:link>
               <xsl:text>
</xsl:text>
            </purl:image>
            <xsl:text>
</xsl:text>
            <xsl:apply-templates 
                  select="race[translate(mydate,'-','')>translate($today,'-','')
   	       and area='ox']"
   	       mode="rdfitem">
               <xsl:sort order="descending" select="mymodified"/>
               <xsl:sort order="ascending" select="location"/>
            </xsl:apply-templates>
         </rdf:RDF>
      </xsl:when>
      <xsl:when test="$version='newnext'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')>translate($today,'-','')
	       and area='ne']">
            <xsl:sort order="descending" select="mymodified"/>
            <xsl:sort order="ascending" select="location"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='oxnewnext'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')>translate($today,'-','')
	       and area='ox']">
            <xsl:sort order="descending" select="mymodified"/>
            <xsl:sort order="ascending" select="location"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='next'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')>translate($today,'-','')
	       and area='ne']">
            <xsl:sort order="ascending" select="myid"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='oxnext'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')>translate($today,'-','')
	       and area='ox']">
            <xsl:sort order="ascending" select="myid"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='pb57'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
               and mytime!='00:00:00'
	       and distance_number='5.7000'
	       and distance_units='M']">
            <xsl:sort order="ascending" select="mytime"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='pb10K'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
               and mytime!='00:00:00'
	       and distance_number='10'
	       and distance_units='K']">
            <xsl:sort order="ascending" select="mytime"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='pb10M'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
               and mytime!='00:00:00'
	       and distance_number='10'
	       and distance_units='M']">
            <xsl:sort order="ascending" select="mytime"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='pbHM'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
               and mytime!='00:00:00'
	       and distance_number='21.0975'
	       and distance_units='K']">
            <xsl:sort order="ascending" select="mytime"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='pb10K2'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
               and translate(mydate,'-','')>'20080101'
               and mytime!='00:00:00'
	       and distance_number='10'
	       and distance_units='K']">
            <xsl:sort order="ascending" select="mytime"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='pb10M2'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
               and translate(mydate,'-','')>'20080101'
               and mytime!='00:00:00'
	       and distance_number='10'
	       and distance_units='M']">
            <xsl:sort order="ascending" select="mytime"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='pbHM2'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
               and translate(mydate,'-','')>'20080101'
               and mytime!='00:00:00'
	       and distance_number='21.0975'
	       and distance_units='K']">
            <xsl:sort order="ascending" select="mytime"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='prev'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
	       and mytime!='00:00:00']">
            <xsl:sort order="descending" select="mydate"/>
            <xsl:sort order="ascending" select="location"/>
         </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$version='rest'">
         <xsl:apply-templates 
               select="race[translate(mydate,'-','')&lt;=translate($today,'-','')
	       and mytime='00:00:00']">
            <xsl:sort order="descending" select="mydate"/>
            <xsl:sort order="ascending" select="location"/>
         </xsl:apply-templates>
      </xsl:when>
   </xsl:choose>
</xsl:template>

<xsl:template match="race" mode="rdfchannel">
   <xsl:variable name="nextfile"> 
      <xsl:choose>
         <xsl:when test="area='ox'">
            <xsl:text>oxnext.htm</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>next.htm</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:variable> 
   <xsl:variable name="name"> 
      <xsl:value-of select="mydate"/>
      <xsl:text>_</xsl:text>
      <xsl:value-of select="translate(location,' ','_')"/>
   </xsl:variable> 
   <xsl:element name="rdf:li"
      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <xsl:attribute name="rdf:resource"
                     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
         <xsl:text>BJCRDFAhttp://www.barrycornelius.com/running/races/</xsl:text>
	 <xsl:value-of select="$nextfile"/>
	 <xsl:text>#</xsl:text><xsl:value-of select="$name"/>
      </xsl:attribute>
   </xsl:element>
   <xsl:text>
</xsl:text>
</xsl:template>

<xsl:template match="race" mode="rdfitem">
   <xsl:variable name="nextfile"> 
      <xsl:choose>
         <xsl:when test="area='ox'">
            <xsl:text>oxnext.htm</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>next.htm</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:variable> 
   <xsl:variable name="name"> 
      <xsl:value-of select="mydate"/>
      <xsl:text>_</xsl:text>
      <xsl:value-of select="translate(location,' ','_')"/>
   </xsl:variable> 
   <purl:item xmlns:purl="http://purl.org/rss/1.0/"
              xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <xsl:attribute name="rdf:about">
         <xsl:text>BJCRDFBhttp://www.barrycornelius.com/running/races/</xsl:text>
	 <xsl:value-of select="$nextfile"/>
	 <xsl:text>#</xsl:text><xsl:value-of select="$name"/>
      </xsl:attribute>
      <purl:title>
         <xsl:value-of select="date:month-abbreviation(concat('--',substring(mymodified,5,2),'--'))"/>
         <xsl:value-of select="substring(mymodified,7,2)"/>
	 <xsl:text>_</xsl:text>
         <xsl:choose>
            <xsl:when test="distance_number='' or distance_number='-' or distance_number='0'">
            </xsl:when>
            <xsl:when test="distance_number='21.0975'">
               <xsl:text>half</xsl:text>
            </xsl:when>
            <xsl:when test="starts-with(distance_number,'42.195')">
               <xsl:text>mara</xsl:text>
            </xsl:when>
            <xsl:when test="distance_number &lt; 10.0">
	       <xsl:text>_</xsl:text>
               <xsl:value-of select="format-number(distance_number,'#.#####')"/>
               <xsl:value-of select="distance_units"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="format-number(distance_number,'#.#####')"/>
               <xsl:value-of select="distance_units"/>
            </xsl:otherwise>
         </xsl:choose>
	 <xsl:text>:</xsl:text>
	 <xsl:value-of select="mydate"/>
	 <xsl:text>:</xsl:text>
	 <xsl:value-of select="location"/>
	 <!--
	 <xsl:value-of select="$name"/>
	 -->
      </purl:title>
      <purl:link>
         <xsl:text>http://www.barrycornelius.com/running/races/</xsl:text>
	 <xsl:value-of select="$nextfile"/>
	 <xsl:text>#</xsl:text><xsl:value-of select="$name"/>
      </purl:link>
   </purl:item>
   <xsl:text>
</xsl:text>
</xsl:template>

<xsl:template name="output_google_location">
   <xsl:if test="starts-with(smap,'x') or starts-with(smap,'X')">
      <xsl:variable name="ll" select="substring(smap, 26, 19)"/>
	       <xsl:value-of select="$ll"/>
   </xsl:if>
               <xsl:text> (</xsl:text>
      	       <xsl:choose>
                  <xsl:when test="location='Brampton to Carlisle'">
	             <xsl:text>Brampton Carlisle</xsl:text>
      	          </xsl:when>
      	          <xsl:otherwise>
	             <xsl:call-template name="url-encode">
	                <xsl:with-param name="str" 
                         select="translate(translate(location,'(',''),')','')"/>
	             </xsl:call-template>
      	          </xsl:otherwise>
      	       </xsl:choose>
               <xsl:text>)</xsl:text>
</xsl:template>

<xsl:template match="race">
   <xsl:variable name="brown" >ee9a4d</xsl:variable>
   <xsl:variable name="yellow">ffff00</xsl:variable>
   <xsl:variable name="grey"  >cccccc</xsl:variable>
   <xsl:variable name="red"   >ff99cc</xsl:variable>
   <xsl:variable name="blue"  >99ffff</xsl:variable>
   <xsl:variable name="green" >ccff66</xsl:variable>
   <xsl:element name="tr">
   <xsl:attribute name="valign">top</xsl:attribute>
   <xsl:choose>
      <xsl:when test="$version='prev' or starts-with($version,'pb') or $version='rest' or runners='-'">
      </xsl:when>
      <xsl:otherwise>
         <xsl:attribute name="bgcolor">
         <xsl:text>#</xsl:text>
         <xsl:choose>
            <xsl:when test="runners='H'">
	    <xsl:value-of select="$green"/>
	    </xsl:when>
            <xsl:when test="runners='h'">
	    <xsl:value-of select="$green"/>
	    </xsl:when>
            <xsl:when test="runners='M'">
	    <xsl:value-of select="$brown"/>
	    </xsl:when>
            <xsl:when test="runners='m'">
	    <xsl:value-of select="$brown"/>
	    </xsl:when>
            <xsl:when test="runners='2'">
	    <xsl:value-of select="$grey"/>
	    </xsl:when>
            <xsl:when test="runners='Z'">
	    <xsl:value-of select="$red"/>
	    </xsl:when>
            <xsl:when test="runners='z'">
	    <xsl:value-of select="$red"/>
	    </xsl:when>
            <xsl:when test="runners='?'">
	    <xsl:value-of select="$blue"/>
	    </xsl:when>
            <xsl:otherwise>
	    <xsl:value-of select="$green"/>
	    </xsl:otherwise>
         </xsl:choose>
         </xsl:attribute>
      </xsl:otherwise>
   </xsl:choose>
   <xsl:choose>
      <xsl:when test="$version='prev' or $version='rest'">
         <td bgcolor="#ffffcc" align="right">
	 <xsl:text>BJCRNB</xsl:text>
	 </td>
      </xsl:when>
      <xsl:when test="starts-with($version,'pb')">
         <td bgcolor="#ffffcc" align="right">
	 <xsl:text>BJCRNF</xsl:text>
	 </td>
      </xsl:when>
   </xsl:choose>
   <td>
   <xsl:variable name="oldlink">
      <xsl:value-of select="mydate"/>
      <xsl:text>_</xsl:text>
      <xsl:value-of select="translate(location,' ','_')"/>
   </xsl:variable>
   <a>
      <xsl:attribute name="name">
         <xsl:value-of select="$oldlink"/>
      </xsl:attribute>
   </a>
   <xsl:if test="myid!=$oldlink">
      <a>
         <xsl:attribute name="name">
            <xsl:value-of select="myid"/>
         </xsl:attribute>
      </a>
   </xsl:if>
   <xsl:value-of select="date:month-abbreviation(mydate)"/>
   <br />
   <xsl:value-of select="number(substring(mydate, 1, 4))"/>
   </td>
   <td>
   <xsl:value-of select="format-number(substring(mydate, 9, 2),'00')"/>
   </td>
   <td>
   <xsl:value-of select="date:day-abbreviation(mydate)"/>
   <xsl:choose>
      <xsl:when test="starttime!='-'">
         <br />
         <xsl:value-of select="starttime"/>
      </xsl:when>
   </xsl:choose>
   </td>
   <td>
   <xsl:value-of select="location"/>
   <br />
   <xsl:choose>
      <xsl:when test="distance_number='' or distance_number='-' or distance_number='0' or distance_number='0.0000'">
      </xsl:when>
      <xsl:when test="distance_number='21.0975'">
      <xsl:text>half marathon</xsl:text>
      </xsl:when>
      <xsl:when test="starts-with(distance_number,'42.195')">
      <xsl:text>marathon</xsl:text>
      </xsl:when>
      <xsl:otherwise>
      <xsl:value-of select="format-number(distance_number,'#.#####')"/>
      <xsl:value-of select="distance_units"/>
      </xsl:otherwise>
   </xsl:choose>
   <xsl:choose>
      <xsl:when test="$version='next' or $version='newnext' or $version='oxnext' or $version='oxnewnext'">
         <br />
         <a class="icalendarurl" style="border: 0">
            <xsl:attribute name="href">
               <xsl:text>view/</xsl:text>
	       <xsl:value-of select="id"/>
               <xsl:text>.ics</xsl:text>
            </xsl:attribute>
	    <img src="http://www.barrycornelius.com/images/icalendar.png" 
	         border="0" alt="iCalendar" title="iCalendar" />
         </a>
         <br />
	 <xsl:variable name="mydate_nh" select="translate(mydate,'-','')"/>
	 <xsl:variable name="factor">
	    <xsl:choose>
	       <xsl:when test=
	             "$mydate_nh &gt; '20060325' and $mydate_nh &lt; '20061029'">
                  <xsl:text>100</xsl:text>
	       </xsl:when>
	       <xsl:when test=
	             "$mydate_nh &gt; '20070324' and $mydate_nh &lt; '20071028'">
                  <xsl:text>100</xsl:text>
	       </xsl:when>
	       <xsl:when test=
	             "$mydate_nh &gt; '20080329' and $mydate_nh &lt; '20081026'">
                  <xsl:text>100</xsl:text>
	       </xsl:when>
	       <xsl:when test=
	             "$mydate_nh &gt; '20090328' and $mydate_nh &lt; '20091025'">
                  <xsl:text>100</xsl:text>
	       </xsl:when>
	       <xsl:when test=
	             "$mydate_nh &gt; '20100327' and $mydate_nh &lt; '20101031'">
                  <xsl:text>100</xsl:text>
	       </xsl:when>
	       <xsl:when test=
	             "$mydate_nh &gt; '20110326' and $mydate_nh &lt; '20111030'">
                  <xsl:text>100</xsl:text>
	       </xsl:when>
	       <xsl:otherwise>
                  <xsl:text>0</xsl:text>
	       </xsl:otherwise>
	    </xsl:choose>
	 </xsl:variable>
	 <xsl:variable name="starttime_utc">
	    <xsl:choose>
	       <xsl:when test="string-length(starttime)=4">
	          <xsl:value-of select="format-number(starttime - $factor,'0000')"/>
	       </xsl:when>
	       <xsl:otherwise>
	          <xsl:value-of select="format-number('0001','0000')"/>
	       </xsl:otherwise>
	    </xsl:choose>
	 </xsl:variable>
	 <xsl:variable name="starttime_google">
            <xsl:value-of
select="concat(translate(mydate,'-',''), 'T', $starttime_utc, '00Z')"/>
	 </xsl:variable>
	 <xsl:variable name="endtime_utc">
	    <xsl:choose>
	       <xsl:when test="string-length(starttime)=4">
	          <xsl:value-of select="format-number($starttime_utc + 100,'0000')"/>
	       </xsl:when>
	       <xsl:otherwise>
	          <xsl:value-of select="format-number('2359','0000')"/>
	       </xsl:otherwise>
	    </xsl:choose>
	 </xsl:variable>
	 <xsl:variable name="endtime_google">
            <xsl:value-of
select="concat(translate(mydate,'-',''), 'T', $endtime_utc, '00Z')"/>
	 </xsl:variable>
         <a class="googleurl" style="border: 0">
            <xsl:attribute name="href">
               <xsl:text>http://www.google.com/calendar/event?action=TEMPLATE</xsl:text>
               <xsl:text>&amp;text=</xsl:text>
               <xsl:variable name="title" select="substring-before(comments, ';')"/>
      	       <xsl:choose>
      	          <xsl:when test="$title=''">
                     <xsl:value-of select="translate(comments,'&quot;','')"/>
      	          </xsl:when>
      	          <xsl:otherwise>
                     <xsl:value-of select="translate($title,'&quot;','')"/>
      	          </xsl:otherwise>
      	       </xsl:choose>
               <xsl:text>&amp;dates=</xsl:text>
	       <xsl:value-of select="$starttime_google"/>
               <xsl:text>/</xsl:text>
	       <xsl:value-of select="$endtime_google"/>
               <xsl:text>&amp;sprop=website:</xsl:text>
               <xsl:text>http://www.barrycornelius.com/running/races/next.htm</xsl:text>
               <xsl:text>&amp;details=</xsl:text>
               <xsl:text>The details of this race are given at </xsl:text>
               <xsl:text>http://www.barrycornelius.com/running/races/next.htm%23</xsl:text>
	       <xsl:value-of select="myid"/>
               <xsl:text>&amp;location=</xsl:text>
               <xsl:call-template name="output_google_location"/>
<!--
   <xsl:if test="starts-with(smap,'x') or starts-with(smap,'X')">
      <xsl:variable name="ll" select="substring(smap, 26, 19)"/>
	       <xsl:value-of select="$ll"/>
   </xsl:if>
               <xsl:text> (</xsl:text>
      	       <xsl:choose>
                  <xsl:when test="location='Brampton to Carlisle'">
	             <xsl:text>Brampton Carlisle</xsl:text>
      	          </xsl:when>
      	          <xsl:otherwise>
	             <xsl:call-template name="url-encode">
	                <xsl:with-param name="str" 
                         select="translate(translate(location,'(',''),')','')"/>
	             </xsl:call-template>
      	          </xsl:otherwise>
      	       </xsl:choose>
               <xsl:text>)</xsl:text>
-->
            </xsl:attribute>
	    <img src="http://www.google.com/calendar/images/ext/gc_button1.gif" 
	         border="0" alt="Google" title="Google" />
         </a> 
      </xsl:when>
   </xsl:choose>
   </td>
   <xsl:choose>
      <xsl:when test="$version='next' or $version='newnext' or $version='oxnext' or $version='oxnewnext'">
         <td>
         <xsl:value-of select="translate(cd,  '_- ',' ?')"/>
         <br />
         <xsl:value-of select="translate(eods,'_- ',' ?')"/>
         <br />
         <xsl:choose>
           <xsl:when test="postcode='-'">
             <xsl:text>?</xsl:text>
           </xsl:when>
           <xsl:otherwise>
             <xsl:call-template name="output_url">
               <xsl:with-param name="url" select="concat('http://maps.google.co.uk/maps?q=', postcode, '&amp;z=14')"/>
               <xsl:with-param name="label" select="postcode"/>
             </xsl:call-template>
           </xsl:otherwise>
         </xsl:choose>
         </td>
      </xsl:when>
   </xsl:choose>
   <xsl:choose>
      <xsl:when test="$version='prev' or starts-with($version,'pb')">
         <td align="right">
         <xsl:call-template name="output_time">
            <xsl:with-param name="time" select="mytime"/>
         </xsl:call-template>
         <br />
         <xsl:choose>
            <xsl:when test="distance_number='0.0000'">
            </xsl:when>
            <xsl:otherwise>
         <xsl:variable name="totalseconds" select="substring(mytime,1,2)*3600+substring(mytime,4,2)*60+substring(mytime,7,2)"/>
         <xsl:variable name="distancemiles">
            <xsl:choose>
               <xsl:when test="distance_units='K'">
                  <xsl:value-of select="distance_number*0.62137119"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="distance_number"/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:variable>
         <xsl:variable name="speed1000" select="1000.0*($totalseconds div 60.0) div $distancemiles"/>
         <xsl:variable name="speedmins" select="floor($speed1000 div 1000.0)"/>
         <xsl:variable name="speedsecs" select="floor(($speed1000 - $speedmins*1000.0)*60.0 div 1000.0)"/>
         <xsl:value-of
         select="concat($speedmins,'m',format-number($speedsecs,'00'),'s')"/>
               </xsl:otherwise>
         </xsl:choose>
         <xsl:choose>
            <xsl:when test="fastesttime!='00:00:00'">
               <br />
               <xsl:call-template name="output_time">
                  <xsl:with-param name="time" select="fastesttime"/>
               </xsl:call-template>
               <br />
               <xsl:variable name="myseconds" select="substring(mytime,1,2)*3600+substring(mytime,4,2)*60+substring(mytime,7,2)"/>
               <xsl:variable name="fastestseconds" select="substring(fastesttime,1,2)*3600+substring(fastesttime,4,2)*60+substring(fastesttime,7,2)"/>
               <xsl:value-of select="format-number($myseconds div $fastestseconds,'0.00')"/>
               <xsl:comment>
               <xsl:text> or </xsl:text>
               <xsl:value-of select="format-number(100.0 * $fastestseconds div $myseconds,'00.00')"/>
               </xsl:comment>
               <xsl:choose>
                  <xsl:when test="distance_number='10' and distance_units='K'">
                  <br />
                  <xsl:variable name="worldseconds" select="27*60 + 20"/>
                  <xsl:value-of select="format-number($fastestseconds div $worldseconds,'0.00')"/>
                  <xsl:comment>
                  <xsl:text> or </xsl:text>
                  <xsl:value-of select="format-number(100.0 * $worldseconds div $fastestseconds,'00.00')"/>
                  </xsl:comment>
                  </xsl:when>
               </xsl:choose>
            </xsl:when>
         </xsl:choose>
         </td>
      </xsl:when>
   </xsl:choose>
   <td>
      <table>
      <xsl:if test="$version='prev' or starts-with($version,'pb')">
         <tr>
         <td>
         <xsl:choose>
            <xsl:when test="runners='-' or runners='?' or runners='z' or runners='2'">
               <xsl:text>-</xsl:text><br />
   	 </xsl:when>
            <xsl:when test="runners='Z'">
               <xsl:text>on my own</xsl:text><br />
            </xsl:when>
            <xsl:otherwise>
               <xsl:choose>
                  <xsl:when test="contains(runners,'X')">
                     <xsl:value-of select="concat(translate(runners,'X',''),'djr')"/><br />
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:value-of select="runners"/><br />
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:otherwise>
         </xsl:choose>
         </td>
         </tr>
      </xsl:if>
      <!--
      <xsl:choose>
         <xsl:when test="travel-dist!='0'">
            <xsl:value-of select="travel-dist"/>M:<xsl:value-of select="concat(number(substring(travel-time,1,2)),'h',format-number(substring(travel-time,4,2),'00'),'m')"/>
            <br />
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>-</xsl:text><br />
         </xsl:otherwise>
      </xsl:choose>
      -->
      <tr>
      <td>
      <xsl:call-template name="output_smap">
         <xsl:with-param name="url" select="smap"/>
      </xsl:call-template>
      </td>
      <td>
      <xsl:choose>
         <xsl:when test="$version='xprev' or starts-with($version,'pb')">
         </xsl:when>
         <xsl:otherwise>
            <xsl:variable name="google_maps_url">
               <xsl:text>maps.google.com/maps?hl=en-GB&amp;q=</xsl:text>
               <xsl:call-template name="output_google_location"/>
            </xsl:variable>
            <xsl:call-template name="output_url">
               <xsl:with-param name="url" select="$google_maps_url"/>
               <xsl:with-param name="label">google</xsl:with-param>
            </xsl:call-template>
         </xsl:otherwise>
      </xsl:choose>
      </td>
      </tr>
      <tr>
      <td>
      <xsl:call-template name="output_url">
         <xsl:with-param name="url" select="raceinfo"/>
         <xsl:with-param name="label">info</xsl:with-param>
      </xsl:call-template>
      </td>
      </tr>
      <tr>
      <td>
      <xsl:call-template name="output_url">
         <xsl:with-param name="url" select="form"/>
         <xsl:with-param name="label">form</xsl:with-param>
      </xsl:call-template>
      </td>
      <td>
      <xsl:call-template name="output_url">
         <xsl:with-param name="url" select="online"/>
         <xsl:with-param name="label">oe-form</xsl:with-param>
      </xsl:call-template>
      </td>
      </tr>
      <tr>
      <td>
      <xsl:choose>
         <xsl:when test="string-length(gpmap)&gt;1">
            <xsl:variable name="fullgpmap"> 
               <xsl:text>www.barrycornelius.com/runningstatic/php/gpintro.php?args=</xsl:text>
               <xsl:variable name="title" select="substring-before(comments, ';')"/>
      	       <xsl:choose>
      	          <xsl:when test="$title=''">
      	          </xsl:when>
      	          <xsl:otherwise>
                     <xsl:value-of select="translate($title,'&quot;','')"/>
      	          </xsl:otherwise>
      	       </xsl:choose>
	       <xsl:text>;</xsl:text>
               <xsl:value-of select="gpmap"/>
            </xsl:variable> 
            <xsl:call-template name="output_url">
               <xsl:with-param name="url" select="$fullgpmap"/>
               <xsl:with-param name="label">gp-map</xsl:with-param>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>-</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
      </td>
      <td>
      <xsl:call-template name="output_url">
         <xsl:with-param name="url" select="map"/>
         <xsl:with-param name="label">map</xsl:with-param>
      </xsl:call-template>
      <!--
      <xsl:if test="$version='next' or $version='newnext' or $version='oxnext' or $version='oxnewnext'">
         <xsl:text>ROUTEROUTE</xsl:text>
      </xsl:if>
      -->
      </td>
      </tr>
      <xsl:if test="$version='prev' or $version='rest' or starts-with($version,'pb')">
         <tr>
         <td>
         <xsl:call-template name="output_url">
            <xsl:with-param name="url" select="results"/>
            <xsl:with-param name="label">results</xsl:with-param>
         </xsl:call-template>
         </td>
         </tr>
      </xsl:if>
      <tr>
      <td>
      <!--
      <xsl:if test="$version='next' or $version='oxnext'">
         <xsl:call-template name="output_forumid"/>
         <xsl:text> </xsl:text><br />
      </xsl:if>
      -->
      <xsl:choose>
         <xsl:when test="$version='next' or $version='newnext' or $version='oxnext' or $version='oxnewnext'">
            <a>
               <xsl:attribute name="href">
                  <xsl:text>update.php?date=</xsl:text>
                  <xsl:value-of select="date:month-abbreviation(concat('--',substring(mymodified,5,2),'--'))"/>
                  <xsl:value-of select="substring(mymodified,7,2)"/>
               </xsl:attribute>
                     <xsl:text>updated</xsl:text>
            </a>
         </xsl:when>
      </xsl:choose>
      </td>
      <td>
      <xsl:call-template name="output_pr"/>
      </td>
      </tr>
      </table>
   </td>
   <td>
   <xsl:choose>
      <xsl:when test="comments!='-'">
         <xsl:value-of disable-output-escaping="yes" select="comments"/>
      </xsl:when>
   </xsl:choose>
   </td>
   <xsl:choose>
      <xsl:when test="$version='prev' or starts-with($version,'pb')">
      <td>
      <xsl:choose>
         <xsl:when test="splits!='-'">
            <xsl:value-of disable-output-escaping="yes" select="splits"/>
         </xsl:when>
      </xsl:choose>
      </td>
      </xsl:when>
   </xsl:choose>
   </xsl:element>
   <xsl:text>&#10;</xsl:text>
</xsl:template>
</xsl:stylesheet>

