<?xml version="1.0"?>
<!-- 
Copyright 2007, Andy Gill.
All rights reserved.

THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="repo_url"/>
  <xsl:output indent="yes" style="xml"/>
  <xsl:preserve-space elements="*"/>
  <xsl:strip-space elements="td"/>
  <xsl:template match="/changelog">
    <rss version="2.0">
        <channel>
           <title>darcs pull <xsl:value-of select="$repo_url"/></title>
           <link><xsl:value-of select="$repo_url"/></link>
           <xsl:apply-templates select="patch[1>=position()]" mode="datemode"/>
           <description>darcs patches in <xsl:value-of select="$repo_url"/></description>
            <xsl:apply-templates select="patch"/>
        </channel>
    </rss>
  </xsl:template>
  <xsl:template match="patch">
     <item>
       <title><xsl:value-of select="name"/></title>
        <xsl:apply-templates select="." mode="datemode"/>
       <author><xsl:value-of select="@author"/></author>
       <guid><xsl:value-of select="@hash"/></guid>
       <xsl:element name="description">
          <xsl:value-of select="'&lt;![CDATA['" disable-output-escaping="yes"/>
          <xsl:apply-templates select="comment"/>
          <xsl:apply-templates select="summary"/>
          <xsl:value-of select="']]>'" disable-output-escaping="yes"/>
       </xsl:element>
     </item>
  </xsl:template>
  <xsl:template match="comment">
     <pre>
          <xsl:value-of select="."/>
     </pre>
  </xsl:template>
  <xsl:template match="summary">
     <table>
     <xsl:for-each select="*">
       <tr>
        <xsl:choose>
        <xsl:when test="name() = 'modify_file'">
           <td><xsl:value-of select="normalize-space(text())"/></td>
           <td>
            <xsl:if test="removed_lines/attribute::num > 0">
            -<xsl:value-of select="removed_lines/attribute::num"/>
            </xsl:if>
            <xsl:if test="added_lines/attribute::num > 0">
            +<xsl:value-of select="added_lines/attribute::num"/>
            </xsl:if>
           </td>
        </xsl:when>
        <xsl:when test="name() = 'move'">
            <td><xsl:value-of select="attribute::to"/></td>
            <td>(moved from <xsl:value-of select="attribute::from"/>)</td>
        </xsl:when>
        <xsl:when test="name() = 'add_file'">
           <td><xsl:value-of select="normalize-space(text())"/></td><td>added</td>
        </xsl:when>
        <xsl:when test="name() = 'add_directory'">
           <td><xsl:value-of select="normalize-space(text())"/></td><td>added directory</td>
        </xsl:when>
        <xsl:when test="name() = 'remove_file'">
           <td><xsl:value-of select="normalize-space(text())"/></td><td>removed</td>
        </xsl:when>
        <xsl:when test="name() = 'remove_directory'">
           <td><xsl:value-of select="normalize-space(text())"/></td><td>removed directory</td>
        </xsl:when>
        <xsl:otherwise>
           <td><xsl:value-of select="normalize-space(text())"/></td>
           <td>???</td>
        </xsl:otherwise>
        </xsl:choose>
       </tr>
     </xsl:for-each>
     </table>
  </xsl:template>
  <xsl:template match="*" mode="datemode">
       <pubDate><xsl:value-of select="concat(substring(@local_date,1,3),', ',substring(@local_date,9,2),' ',substring(@local_date,5,3),' ',substring(@local_date,25,4),' ',substring(@local_date,12,8),' ',substring(@local_date,21,3))"/></pubDate>
  </xsl:template>

</xsl:stylesheet>
