<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
	version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:syn="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:date="http://exslt.org/dates-and-times"
	xmlns="http://www.w3.org/2005/Atom"
	extension-element-prefixes="date" 
	exclude-result-prefixes="syn"
>

<!-- the main feed -->

<xsl:variable name="source-url" select="'http://use.perl.org/journal.pl?op=top;content_type=atom'" />
<xsl:variable name="no-tidy" select="1" />

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

<xsl:template match="
	atom:entry
	| text()[ following-sibling::*[1][ self::atom:entry or self::syn:* ] ]
	| atom:feed/atom:link[ @rel = 'self' ]
" />

<xsl:template match="atom:feed">
	<xsl:copy>
		<xsl:apply-templates select="node()|@*"/>
		<xsl:if test="not( atom:icon )">
			<icon>http://use.perl.org/favicon.ico</icon>
		</xsl:if>
		<link rel="self" href="http://plasmasturm.org/feeds/planet-useperl/"/>
		<xsl:for-each select="atom:entry/atom:link/@href">
			<xsl:apply-templates select="document( concat( substring-before( ., '?' ), 'atom' ) )/atom:feed/atom:entry" mode="subdoc" />
		</xsl:for-each>
	</xsl:copy>
</xsl:template>

<!-- individual feeds -->

<xsl:variable name="cutoff" select="24 * 60 * 60" /> <!-- drop entries older than 1 day -->

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

<xsl:template match="atom:entry" mode="subdoc">
	<xsl:if test="date:seconds( date:difference( atom:updated, date:date-time() ) ) &lt; $cutoff">
		<xsl:copy>
			<xsl:text>&#10;</xsl:text>
			<source>
				<xsl:copy-of select="../atom:link | ../atom:id | ../atom:updated" />
			</source>
			<xsl:apply-templates select="node()|@*" mode="subdoc" />
		</xsl:copy>
		<xsl:text>&#10;&#10;</xsl:text>
	</xsl:if>
</xsl:template>

<xsl:template match="atom:entry/atom:title" mode="subdoc">
	<xsl:copy>
		<xsl:value-of select="concat( '[', ../atom:author/atom:name, '] ' )" />
		<xsl:apply-templates select="node()|@*" mode="subdoc" />
	</xsl:copy>
</xsl:template>

<!-- feed source information -->

</xsl:stylesheet>
