<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="http://www.w3.org/2002/02/style-xsl.css" type="text/css"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:an="http://www.w3.org/2003/05/tr-history/analysis#"
 xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#"
 xmlns:org="http://www.w3.org/2001/04/roadmap/org#"
 xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:rec="http://www.w3.org/2001/02pd/rec54#"
 xmlns:xlink="http://www.w3.org/1999/xlink"
 xmlns:hist="http://www.w3.org/2003/05/tr-history/s#"
 xmlns:saxon="http://icl.com/saxon"
 xmlns="http://www.w3.org/2000/svg"
 version="1.0"
 extension-element-prefixes="saxon">

 <!-- graph, broken down into types of TR's produced per quarter -->
 <!-- compute year and quarter locations in graph -->
 <!-- pick a reasonable scale on by which to draw -->
 <!-- decide whether these are side-by-side or vertically stacked bars -->
 <!-- use tr-automation/rec-history.rdf and tr-history/current-tr-history.rdf
      as data sources, use count(....substring(dc:date,1,4)=$year and substring
      (dc:date,6,2)>=$quarter-start and substring(dc:date,6,2)<=$quarter-end)
 -->

 <xsl:output method="xml" encoding="utf-8" indent="yes"/>

 <xsl:param name="end-year"/>
 <xsl:param name="end-quarter"/>

 <xsl:variable name="rectrdb" select="document('http://www.w3.org/2002/01/tr-automation/rec-history.rdf')"/>
 <xsl:variable name="alltrdb" select="document('http://www.w3.org/2003/05/tr-history/current-tr-history.rdf')"/>
 <xsl:variable name="beginning" select="'1995-11-17'"/>

 <xsl:variable name="height" select="'500'"/>

 <xsl:template match="/">
  <xsl:processing-instruction name="xml-stylesheet">href="http://www.w3.org/2003/05/tr-history/svg-history.css" type="text/css"</xsl:processing-instruction>
  <svg viewBox="-80 -50 2900 500">
   <title>
    W3C TR Productivity by Quarter
   </title>
   <defs>
    <linearGradient id="wdgrad">
     <stop offset="5%" stop-color="#c9f"/>
     <stop offset="95%" stop-color="#fff"/>
    </linearGradient>
    <rect height="50" id="WDbox" width="120" fill="url(#wdgrad)"/>
    <linearGradient id="lcgrad">
     <stop offset="5%" stop-color="#fcc"/>
     <stop offset="95%" stop-color="#fff"/>
    </linearGradient>
    <rect height="50" id="LastCallbox" width="120" fill="url(#lcgrad)"/>
    <linearGradient id="crgrad">
     <stop offset="5%" stop-color="#fa0"/>
     <stop offset="95%" stop-color="#fff"/>
    </linearGradient>
    <rect height="50" id="CRbox" width="120" fill="url(#crgrad)"/>
    <linearGradient id="prgrad">
     <stop offset="5%" stop-color="#ff6"/>
     <stop offset="95%" stop-color="#fff"/>
    </linearGradient>
    <rect height="50" id="PRbox" width="120" fill="url(#prgrad)"/>
   </defs>
   <xsl:call-template name="header"/>
   <g id="bars" transform="translate(-325,0)">
    <xsl:call-template name="draw-bars">
     <xsl:with-param name="year" select="'1995'"/>
     <xsl:with-param name="quarter" select="'4'"/>
    </xsl:call-template>
   </g>
  </svg>
 </xsl:template>

 <xsl:template name="draw-bars">
  <xsl:param name="year"/>
  <xsl:param name="quarter"/>
  <xsl:variable name="next-year">
   <xsl:choose>
    <xsl:when test="$quarter&lt;4">
     <xsl:value-of select="$year"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="$year+1"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="next-quarter">
   <xsl:choose>
    <xsl:when test="$quarter&lt;4">
     <xsl:value-of select="$quarter+1"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="'1'"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <rect class="WD" height="{(count($rectrdb//rec:WD[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:WD[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" y="{500-(count($rectrdb//rec:WD[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:WD[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" width="23" x="{($year - 1995)*372 + ($quarter - 1)*93}"/>
  <rect class="CR" height="{(count($rectrdb//rec:CR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:CR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" y="{500-(count($rectrdb//rec:CR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:CR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" width="23" x="{($year - 1995)*372 + ($quarter - 1)*93 + 23}"/>
  <rect class="PR" height="{(count($rectrdb//rec:PR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:PR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" y="{500-(count($rectrdb//rec:PR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:PR[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" width="23" x="{($year - 1995)*372 + ($quarter - 1)*93 + 2*23}"/>
  <rect class="REC" height="{(count($rectrdb//rec:REC[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:REC[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" y="{500-(count($rectrdb//rec:REC[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]) + count($alltrdb//rec:REC[substring(dc:date,1,4)=$year and substring(dc:date,6,2)&gt;=(($quarter * 3) - 2) and substring(dc:date,6,2)&lt;=($quarter * 3)]))*10}" width="24" x="{($year - 1995)*372 + ($quarter - 1)*93 + 3*23}"/>
  <xsl:choose>
   <xsl:when test="$year=$end-year and $quarter=$end-quarter">
    <xsl:value-of select="''"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:call-template name="draw-bars">
     <xsl:with-param name="year" select="$next-year"/>
     <xsl:with-param name="quarter" select="$next-quarter"/>
    </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <xsl:template name="approximate-date-difference">
  <xsl:param name="start-date"/>
  <xsl:param name="end-date"/>
  <xsl:variable name="year-diff">
   <xsl:choose>
    <xsl:when test="substring($end-date,1,4) - substring($start-date,1,4)&lt;=1">
     <xsl:value-of select="'0'"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="(substring($end-date,1,4) - substring($start-date,1,4) - 1) * 372"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>

  <xsl:variable name="month-diff">
   <xsl:choose>
    <xsl:when test="substring($end-date,1,4)-substring($start-date,1,4)=0">
     <xsl:choose>
      <xsl:when test="substring($end-date,6,2)-substring($start-date,6,2)=0">
       <xsl:value-of select="substring($end-date,9,2)-substring($start-date,9,2)"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="(substring($end-date,6,2) - substring($start-date,6,2)) * 31 + substring($start-date,9,2) - (31 - substring($end-date,9,2))"/>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="(substring($end-date,6,2) - 1) * 31 + substring($end-date,9,2) + (12 - substring($start-date,6,2)) * 31 + (31 - substring($start-date,9,2))"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>

  <xsl:value-of select="$year-diff + $month-diff"/>
 </xsl:template>

 <xsl:template name="header">
  <xsl:variable name="y1996">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'1996-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="y1997">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'1997-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="y1998">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'1998-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="y1999">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'1999-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="y2000">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'2000-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="y2001">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'2001-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="y2002">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'2002-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="y2003">
   <xsl:call-template name="approximate-date-difference">
    <xsl:with-param name="start-date" select="$beginning"/>
    <xsl:with-param name="end-date" select="'2003-01-01'"/>
   </xsl:call-template>
  </xsl:variable>
  <g id="years">
   <text x="{$y1996}" y="-20" class="year">1996</text>
   <line x1="{$y1996}" y1="0" x2="{$y1996}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y1996+93}" y1="0" x2="{$y1996+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1996+186}" y1="0" x2="{$y1996+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1996+279}" y1="0" x2="{$y1996+279}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <text x="{$y1997}" y="-20" class="year">1997</text>
   <line x1="{$y1997}" y1="0" x2="{$y1997}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y1997+93}" y1="0" x2="{$y1997+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1997+186}" y1="0" x2="{$y1997+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1997+279}" y1="0" x2="{$y1997+279}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <text x="{$y1998}" y="-20" class="year">1998</text>
   <line x1="{$y1998}" y1="0" x2="{$y1998}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y1998+93}" y1="0" x2="{$y1998+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1998+186}" y1="0" x2="{$y1998+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1998+279}" y1="0" x2="{$y1998+279}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <text x="{$y1999}" y="-20" class="year">1999</text>
   <line x1="{$y1999}" y1="0" x2="{$y1999}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y1999+93}" y1="0" x2="{$y1999+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1999+186}" y1="0" x2="{$y1999+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y1999+279}" y1="0" x2="{$y1999+279}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <text x="{$y2000}" y="-20" class="year">2000</text>
   <line x1="{$y2000}" y1="0" x2="{$y2000}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y2000+93}" y1="0" x2="{$y2000+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y2000+186}" y1="0" x2="{$y2000+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y2000+279}" y1="0" x2="{$y2000+279}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <text x="{$y2001}" y="-20" class="year">2001</text>
   <line x1="{$y2001}" y1="0" x2="{$y2001}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y2001+93}" y1="0" x2="{$y2001+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y2001+186}" y1="0" x2="{$y2001+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y2001+279}" y1="0" x2="{$y2001+279}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <text x="{$y2002}" y="-20" class="year">2002</text>
   <line x1="{$y2002}" y1="0" x2="{$y2002}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y2002+93}" y1="0" x2="{$y2002+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y2002+186}" y1="0" x2="{$y2002+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y2002+279}" y1="0" x2="{$y2002+279}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <text x="{$y2003}" y="-20" class="year">2003</text>
   <line x1="{$y2003}" y1="0" x2="{$y2003}" y2="{$height}" stroke="#333" stroke-width="1"/>
   <line x1="{$y2003+93}" y1="0" x2="{$y2003+93}" y2="{$height}" stroke="#999" stroke-width="1"/>
   <line x1="{$y2003+186}" y1="0" x2="{$y2003+186}" y2="{$height}" stroke="#999" stroke-width="1"/>
  </g>
  <g id="count">
   <line x1="-50" y1="450" x2="2836" y2="450" stroke="#999"/>
   <text x="-50" y="450">5</text>
   <line x1="-50" y1="400" x2="2836" y2="400" stroke="#999"/>
   <text x="-50" y="400">10</text>
   <line x1="-50" y1="350" x2="2836" y2="350" stroke="#999"/>
   <text x="-50" y="350">15</text>
   <line x1="-50" y1="300" x2="2836" y2="300" stroke="#999"/>
   <text x="-50" y="300">20</text>
   <line x1="-50" y1="250" x2="2836" y2="250" stroke="#999"/>
   <text x="-50" y="250">25</text>
   <line x1="-50" y1="200" x2="2836" y2="200" stroke="#999"/>
   <text x="-50" y="200">30</text>
   <line x1="-50" y1="150" x2="2836" y2="150" stroke="#999"/>
   <text x="-50" y="150">35</text>
   <line x1="-50" y1="100" x2="2836" y2="100" stroke="#999"/>
   <text x="-50" y="100">40</text>
   <line x1="-50" y1="50" x2="2836" y2="50" stroke="#999"/>
   <text x="-50" y="50">45</text>
   <line x1="-50" y1="0" x2="2836" y2="0" stroke="#999"/>
   <text x="-50" y="0">50</text>
  </g>
 </xsl:template>
</xsl:stylesheet>
