+ <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="&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:variable name="srchref">
+ <xslt:text>./sources</xslt:text>
+ <xslt:choose>
+ <xslt:when test="substring($entryhref, string-length($entryhref))='/'">
+ <xslt:value-of select="substring($entryhref, 1, string-length($entryhref) - 1)"/>
+ <xslt:text>.xml</xslt:text>
+ </xslt:when>
+ <xslt:when test="substring($entryhref, string-length($entryhref) - 4)='.html'">
+ <xslt:value-of select="substring($entryhref, 1, string-length($entryhref) - 4)"/>
+ <xslt:text>xml</xslt:text>
+ </xslt:when>
+ <xslt:otherwise>
+ <xslt:value-of select="$entryhref"/>
+ </xslt:otherwise>
+ </xslt:choose>
+ </xslt:variable>
+ <xslt:variable name="srcdoc" select="document($srchref)"/>
+ <xslt:text>
	</xslt:text>
+ <entry xmlns="&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>
+ <xslt:choose>
+ <xslt:when test="$srcdoc//*[@itemprop='shrine-id']">
+ <xslt:apply-templates select="$srcdoc//*[@itemprop='shrine-id'][1]" mode="microdata">
+ <xslt:with-param name="tagname" select="'id'"/>
+ <xslt:with-param name="namespace" select="'&Atom;'"/>
+ <xslt:with-param name="plaintext" select="true()"/>
+ </xslt:apply-templates>
+ </xslt:when>
+ <xslt:otherwise>
+ <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:otherwise>
+ </xslt:choose>
+ </xslt:if>
+ <xslt:if test="not(atom:title)">
+ <xslt:text>
		</xslt:text>
+ <xslt:choose>
+ <xslt:when test="$srcdoc//*[@itemprop='shrine-title']">
+ <xslt:apply-templates select="$srcdoc//*[@itemprop='shrine-title'][1]" mode="microdata">
+ <xslt:with-param name="tagname" select="'title'"/>
+ <xslt:with-param name="namespace" select="'&Atom;'"/>
+ </xslt:apply-templates>
+ </xslt:when>
+ <xslt:when test="$srcdoc//html:h1">
+ <xslt:apply-templates select="$srcdoc//html:h1[1]" mode="microdata">
+ <xslt:with-param name="tagname" select="'title'"/>
+ <xslt:with-param name="namespace" select="'&Atom;'"/>
+ </xslt:apply-templates>
+ </xslt:when>
+ <xslt:when test="$srcdoc//html:title">
+ <xslt:apply-templates select="$srcdoc//html:title[1]" mode="microdata">
+ <xslt:with-param name="tagname" select="'title'"/>
+ <xslt:with-param name="namespace" select="'&Atom;'"/>
+ </xslt:apply-templates>
+ </xslt:when>
+ <xslt:otherwise>
+ <title xml:lang="en">Untitled</title>
+ </xslt:otherwise>
+ </xslt:choose>
+ </xslt:if>
+ <xslt:if test="not(atom:updated)">
+ <xslt:text>
		</xslt:text>
+ <xslt:choose>
+ <xslt:when test="$srcdoc//*[@itemprop='shrine-updated']">
+ <xslt:apply-templates select="$srcdoc//*[@itemprop='shrine-updated'][1]" mode="microdata">
+ <xslt:with-param name="tagname" select="'updated'"/>
+ <xslt:with-param name="namespace" select="'&Atom;'"/>
+ <xslt:with-param name="plaintext" select="true()"/>
+ </xslt:apply-templates>
+ </xslt:when>
+ <xslt:otherwise>
+ <xslt:value-of select="$datetime"/>
+ </xslt:otherwise>
+ </xslt:choose>
+ </xslt:if>
+ <xslt:text>
	</xslt:text> <!-- newline before close tag -->
+ </entry>
+ </xslt:template>
+
+ <!--
+ Process feed link elements.
+ This simply rewrites relative links to be absolute.
+ -->
+ <xslt:template match="atom:link[starts-with(@href, '/')]" mode="feed">
+ <link xmlns="&Atom;" rel="{@rel}" href="{$baseiri}{@href}">
+ <xslt:for-each select="@*[local-name()!='rel' and local-name()!='href']">
+ <xslt:copy/>
+ </xslt:for-each>
+ </link>