<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:h="http://www.w3.org/1999/xhtml"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns="http://purl.org/rss/1.0/"
  exclude-result-prefixes="h">

<xsl:output method="xml" encoding="UTF-8" indent="yes"
  media-type="application/rdf+xml"
/>

<xsl:param name="host" select="'validator.w3.org'"/>
<xsl:param name="self" select="concat('http://', $host, '/whatsnew.rss1')"/>
<xsl:param name="validator" 
    select="concat('http://', $host, '/whatsnew.html')"/>
<xsl:param name="desc"
    select="'Recent changes to the W3C Markup Validation Service'"/>
<!-- number of entries to be displayed in the feed -->
<xsl:param name="limit" select="10"/>
<xsl:param name="author" select="'The W3C Validator Team'"/>
<!-- 
  feedvalidator.org complains about dates like YYYY-MM-DD not 
  being valid ISO datetimes, so we hack around it by setting 
  each item's publish time to 00:00:00 UTC
-->
<xsl:param name="faketime" select="'T00:00:00Z'"/>

<xsl:template match="/">
<rdf:RDF>
  <channel rdf:about="{$self}">
    <title><xsl:value-of select="/h:html/h:head/h:title"/></title>
    <link><xsl:value-of select="$validator"/></link>
    <description><xsl:value-of select="$desc"/></description>
    <dc:publisher><xsl:value-of select="$author"/></dc:publisher>
    <dc:date><xsl:value-of
	select="concat(substring-after(/h:html/h:body/*//h:dt[position()=1]/@id,
		't'), $faketime)"/></dc:date>
    <items>
      <xsl:call-template name="itemList"/>
    </items>
  </channel>

  <!-- entries -->
  <xsl:apply-templates select="//h:dt[position() &lt; $limit]"/>
</rdf:RDF>
</xsl:template>

<xsl:template name="itemList">
  <rdf:Seq>
    <xsl:for-each select="//h:dt[position() &lt; $limit]">
      <rdf:li resource="{concat($validator, '#', @id)}"/>
    </xsl:for-each>
  </rdf:Seq>
</xsl:template>

<xsl:template match="h:dt">
<xsl:variable name="updated" select="substring-after(@id, 't')"/>
  <item rdf:about="{concat($validator, '#', @id)}">
    <dc:date><xsl:value-of select="concat($updated, $faketime)"/></dc:date>
    <link><xsl:value-of select="concat($validator, '#', @id)"/></link>
    <title><xsl:value-of select="substring-before(., ':')"/></title>
    <description>
      <xsl:copy-of 
	  select="following::h:dd[position()=1]//text()"/>
    </description>
  </item>
</xsl:template>

<xsl:template match="text()">
</xsl:template>

</xsl:stylesheet>
