<?xml version="1.0" encoding="utf-8"?>
<!-- Written by Aristotle Pagaltzis -->
<!-- This code is in the public domain -->
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:date="http://exslt.org/dates-and-times"
	xmlns:html="http://www.w3.org/1999/xhtml"
	xmlns="http://www.w3.org/2005/Atom"
	extension-element-prefixes="date"
	exclude-result-prefixes="html"
>
<xsl:output method="xml" indent="no" omit-xml-declaration="no" encoding="utf-8" />
<xsl:strip-space elements="*" />

<xsl:template match="node()|@*">
	<xsl:apply-templates select="node()|@*"/>
</xsl:template>

<xsl:template match="html:h3[ @class = 'review_header' ]" mode="found">
	<xsl:variable name="plural" select="/.." />
	<title>
		<xsl:value-of select="normalize-space()" />
		<xsl:if test="html:img">
			<xsl:variable name="stars" select="string-length( html:img/@alt )" />
			<xsl:text> — </xsl:text>
			<xsl:value-of select="$stars" />
			<xsl:text> star</xsl:text>
			<xsl:if test="number( $stars ) != 1">s</xsl:if>
		</xsl:if>
	</title>
</xsl:template>

<xsl:template match="html:blockquote[ @class = 'review' ]" mode="found">
	<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><xsl:copy-of select="node()" /></div></content>
</xsl:template>

<xsl:template match="html:p[ html:span[ @class = 'helpfulq' ] ]">
	<xsl:variable name="perma" select="following-sibling::html:a[ starts-with( @href, '/dist/' ) ][1]"/>
	<xsl:variable name="author" select="html:a[ starts-with( @href, '/user/' ) ]"/>
	<entry>
		<xsl:apply-templates select="preceding-sibling::html:h3[ @class='review_header' ][1]" mode="found" />
		<link href="http://cpanratings.perl.org{ $perma/@href }"/>
		<author>
			<name><xsl:value-of select="$author/text()" /></name>
			<uri>http://cpanratings.perl.org<xsl:value-of select="$author/@href" /></uri>
		</author>
		<id>http://cpanratings.perl.org<xsl:value-of select="concat( $perma/@href, '?', $author/@href )" /></id>
		<updated><xsl:value-of select="concat( translate( substring-after( text()[1], ' - ' ), ' ', 'T' ), '-08:00' )" /></updated>
		<xsl:apply-templates select="preceding-sibling::html:blockquote[ @class='review' ][1]" mode="found" />
	</entry>
</xsl:template>

<xsl:variable name="source-url" select="'http://cpanratings.perl.org/'" />
<xsl:variable name="tidy-arg" select="'-utf8'" />

<xsl:template match="/">
	<feed>
		<title type="xhtml">
			<div xmlns="http://www.w3.org/1999/xhtml">Ratings and Reviews for <abbr title="Comprehensive Perl Archive Network">CPAN</abbr></div>
		</title>
		<subtitle>Recent reviews</subtitle>
		<icon><xsl:value-of select="$source-url" />favicon.ico</icon>
		<id>urn:uuid:bf5f5bb4-1120-11da-9fcb-dd680b0526e0</id>
		<link href="{$source-url}"/>
		<link rel="self" href="http://plasmasturm.org/feeds/cpanratings/"/>
		<updated><xsl:value-of select="date:date-time()" /></updated>
		<xsl:apply-templates />
	</feed>
</xsl:template>

</xsl:stylesheet>
