+ <xslt:apply-templates select="$source/*" mode="content"/>
+ </xslt:template>
+
+ <!--
+ Process feed elements and text.
+ By default, just make a copy.
+ This behaviour will be overridden for certain elements to generate feed metadata.
+ -->
+ <xslt:template match="*|text()" mode="feed">
+ <xslt:copy>
+ <xslt:for-each select="@*">
+ <xslt:copy/>
+ </xslt:for-each>
+ <xslt:apply-templates mode="feed"/>
+ </xslt:copy>
+ </xslt:template>
+
+ <!--
+ Process the root feed element.
+ This adds required metadata when it has not been provided in the source X·M·L.
+ -->
+ <xslt:template match="atom:feed" mode="feed">
+ <xslt:text>
</xslt:text> <!-- ensure a newline between the doctype and the feed element -->
+ <feed xmlns="http://www.w3.org/2005/Atom">
+ <xslt:for-each select="@*">
+ <xslt:copy/>
+ </xslt:for-each>
+ <xslt:apply-templates select="text()[following-sibling::*[not(self::atom:entry)]]|*[not(self::atom:entry)]" mode="feed"/>
+ <xslt:if test="not(atom:id)">
+ <xslt:text>
	</xslt:text>
+ <id>
+ <xslt:choose>
+ <xslt:when test="contains($baseiri, '://')">
+ <xslt:text>oai:</xslt:text>
+ <xslt:value-of select="substring-after($baseiri, '://')"/>
+ <xslt:text>:</xslt:text>
+ </xslt:when>
+ <xslt:otherwise>
+ <xslt:value-of select="$baseiri"/>
+ <xslt:text>/</xslt:text>
+ </xslt:otherwise>
+ </xslt:choose>
+ <xslt:value-of select="$outputpath"/>
+ </id>
+ </xslt:if>
+ <xslt:if test="not(atom:title)">
+ <xslt:text>
	</xslt:text>
+ <title xml:lang="en">Untitled</title>
+ </xslt:if>
+ <xslt:if test="not(atom:author)">
+ <xslt:text>
	</xslt:text>
+ <author>
+ <name xml:lang="en">Anonymous</name>
+ </author>
+ </xslt:if>
+ <xslt:if test="not(atom:link[@rel='alternate'][@type='text/html'])">
+ <xslt:text>
	</xslt:text>
+ <link rel="alternate" type="text/html" href="{$baseiri}/"/>
+ </xslt:if>
+ <xslt:if test="not(atom:link[@rel='self'])">
+ <xslt:text>
	</xslt:text>
+ <link rel="self" type="application/atom+xml" href="{$baseiri}{$outputpath}"/>
+ </xslt:if>
+ <xslt:if test="not(atom:updated)">
+ <xslt:text>
	</xslt:text>
+ <updated>
+ <xslt:value-of select="$datetime"/>
+ </updated>
+ </xslt:if>
+ <xslt:if test="not(atom:generator)">
+ <xslt:text>
	</xslt:text>
+ <generator uri="https://github.com/marrus-sh/shrine-xslt">shrine-xslt</generator>
+ </xslt:if>
+ <xslt:apply-templates select="atom:entry" mode="feed"/>
+ <xslt:text>
</xslt:text> <!-- newline before close tag -->
+ </feed>
+ </xslt:template>
+
+ <!--
+ Process feed entry elements.
+ -->
+ <xslt:template match="atom:entry[atom:link[@rel='alternate'][starts-with(@href, '/')][@type='text/html']]" mode="feed">
+ <xslt:variable name="entryhref" select="atom:link[@rel='alternate'][starts-with(@href, '/')][@type='text/html'][1]/@href"/>
+ <xslt:text>
	</xslt:text>
+ <entry xmlns="http://www.w3.org/2005/Atom">
+ <xslt:for-each select="@*">
+ <xslt:copy/>
+ </xslt:for-each>
+ <xslt:apply-templates select="text()[following-sibling::*]|*" mode="feed"/>
+ <xslt:if test="not(atom:id)">
+ <xslt:text>
		</xslt:text>
+ <id>
+ <xslt:choose>
+ <xslt:when test="contains($baseiri, '://')">
+ <xslt:text>oai:</xslt:text>
+ <xslt:value-of select="substring-after($baseiri, '://')"/>
+ <xslt:text>:</xslt:text>
+ </xslt:when>
+ <xslt:otherwise>
+ <xslt:value-of select="$baseiri"/>
+ <xslt:text>/</xslt:text>
+ </xslt:otherwise>
+ </xslt:choose>
+ <xslt:value-of select="$entryhref"/>
+ </id>
+ </xslt:if>
+ <xslt:if test="not(atom:title)">
+ <xslt:text>
		</xslt:text>
+ <title xml:lang="en">Untitled</title>
+ </xslt:if>
+ <xslt:if test="not(atom:updated)">
+ <xslt:text>
		</xslt:text>
+ <updated>
+ <xslt:value-of select="$datetime"/>
+ </updated>
+ </xslt:if>
+ <xslt:text>
	</xslt:text> <!-- newline before close tag -->
+ </entry>
+ </xslt:template>
+
+ <!--
+ Process feed link elements.
+ This simply rewrites absolute links to be relative.
+ -->
+ <xslt:template match="atom:link[starts-with(@href, '/')]" mode="feed">
+ <link xmlns="http://www.w3.org/2005/Atom" rel="{@rel}" href="{$baseiri}{@href}">
+ <xslt:for-each select="@*[local-name()!='rel' and local-name()!='href']">
+ <xslt:copy/>
+ </xslt:for-each>
+ </link>