+<!-- Add rel attributes to external links -->
+<xsl:template match='xhtml:a[starts-with(@href,"http://")
+ or starts-with(@href,"https://")
+ or starts-with(@href,"//")]'>
+ <xsl:variable name='domain'
+ select='substring-before(
+ concat(translate(substring-after(@href, "//"), ":", "/"), "/"),
+ "/")' />
+
+ <xsl:copy>
+ <xsl:apply-templates select='@*' />
+ <xsl:if test='not($domain="draconx.ca"
+ or f:ends-with($domain, ".draconx.ca"))'>
+ <xsl:attribute name='rel'>
+ <xsl:if test='@rel'>
+ <xsl:value-of select='@rel' />
+ <xsl:text> </xsl:text>
+ </xsl:if>
+ <xsl:text>external noopener noreferrer</xsl:text>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates select='node()' />
+ </xsl:copy>
+</xsl:template>
+
+<xsl:template match='xhtml:h2[@id]'>
+ <xsl:variable name='fragment' select='concat("#", @id)' />
+ <xsl:copy>
+ <xsl:apply-templates select='node()|@*' />
+ <xsl:text> </xsl:text>
+ <small class='permalink'>
+ (<a href='{$fragment}'><xsl:value-of select='$fragment' /></a>)
+ </small>
+ </xsl:copy>
+</xsl:template>
+
+<xsl:template match='copyright'>
+ <p>
+ <xsl:text>Copyright © </xsl:text>
+ <xsl:value-of select='text()' />
+ <xsl:text>.</xsl:text>
+ </p>
+</xsl:template>
+
+<xsl:template match='license'>
+ <p>
+ <xsl:text>Copying and distribution of this material</xsl:text>
+ <xsl:if test='normalize-space(modification-allowed)="yes"'>
+ <xsl:text>, with or without modification,</xsl:text>
+ </xsl:if>
+ <xsl:text> is permitted under the terms of the </xsl:text>
+ <a rel='license'>
+ <xsl:attribute name='href'>
+ <xsl:value-of select='normalize-space(uri)' />
+ </xsl:attribute>
+ <xsl:value-of select='name' />
+ </a>
+ <xsl:text>.</xsl:text>
+ </p>
+</xsl:template>
+
+<xsl:template match='source'>
+ <p>
+ <xsl:text>This document was compiled from </xsl:text>
+ <a href='{concat($source-uri, revision, ":", file)}'>
+ <xsl:value-of select='file' />
+ </a>
+ <xsl:text> on </xsl:text>
+ <xsl:value-of select='compiletime' />
+ <xsl:text>.</xsl:text>
+ </p>
+</xsl:template>
+