<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="microsummary-generator.xsl" type="text/xsl"?>
<generator xmlns="http://www.mozilla.org/microsummaries/0.1" name="Alexa Traffic Ranking">
  <template>
    <transform xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <output method="text"/>
      <template match="/">
        <!-- The site being ranked. -->
        <value-of select="id('content')/table[1]/tbody/tr/td[1]/table/tbody/tr/td[1]/span[1]"/>
        <text>: </text>

        <!-- The daily traffic ranking. -->
        <!-- To get this, we first find the h2 header that reads
           - "Traffic Rank for [site]", then we walk the tree to its succeeding
           - table, which contains the rank in a specific cell.
           -->
        <variable name="daily" select="normalize-space(//h2[contains(., 'Traffic Rank for')]/following-sibling::table[position()=1]/tbody/tr[2]/td[1])"/>

        <!-- Only the top 100k sites have a daily ranking, so we show
           - the weekly ranking for the rest.
           -->
        <choose>
          <when test="$daily = 'N/A*'">
            <!-- The weekly traffic ranking. -->
            <value-of select="normalize-space(//h2[contains(., 'Traffic Rank for')]/following-sibling::table[position()=1]/tbody/tr[2]/td[2])"/>
          </when>
          <otherwise>
            <value-of select="$daily"/>
          </otherwise>
        </choose>
      </template>
    </transform>
  </template>

  <pages>
    <include>^http://www\.alexa\.com/data/details/traffic_details\?.*url=</include>
  </pages>

  <!-- Update four times a day. -->
  <update interval="360"/>
</generator>

