1 <?xml version='1.0' encoding='UTF-8' ?>
3 Nick's web site: Final XHTML output stage
5 Copyright © 2018 Nick Bowler
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>
20 <xsl:stylesheet version='1.0'
21 xmlns='http://www.w3.org/1999/xhtml'
22 xmlns:xhtml='http://www.w3.org/1999/xhtml'
23 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
24 xmlns:func='http://exslt.org/functions'
25 xmlns:f='http://draconx.ca/my-functions'
26 extension-element-prefixes='func f'
27 exclude-result-prefixes='xhtml'>
29 <xsl:output method='xml' encoding='UTF-8' indent='yes'
30 doctype-public='-//W3C//DTD XHTML 1.1//EN'
31 doctype-system='http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd' />
32 <xsl:strip-space elements='*' />
33 <xsl:preserve-space elements='xhtml:p' />
35 <xsl:param name='source-uri'
36 select='"//git.draconx.ca/gitweb/homepage.git/blob/"' />
37 <xsl:param name='site-title' select='"The Citrine Citadel"' />
39 <func:function name='f:ends-with'>
40 <xsl:param name='a' />
41 <xsl:param name='b' />
43 select='substring($a, string-length($a)-string-length($b)+1)=$b' />
46 <xsl:template match='node()|@*'>
47 <xsl:copy><xsl:apply-templates select='node()|@*' /></xsl:copy>
50 <!-- Add rel attributes to external links -->
51 <xsl:template match='xhtml:a[starts-with(@href,"http://")
52 or starts-with(@href,"https://")
53 or starts-with(@href,"//")]'>
54 <xsl:variable name='domain'
55 select='substring-before(
56 concat(translate(substring-after(@href, "//"), ":", "/"), "/"),
60 <xsl:apply-templates select='@*' />
61 <xsl:if test='not($domain="draconx.ca"
62 or f:ends-with($domain, ".draconx.ca"))'>
63 <xsl:attribute name='rel'>
65 <xsl:value-of select='@rel' />
66 <xsl:text> </xsl:text>
68 <xsl:text>external noopener noreferrer</xsl:text>
71 <xsl:apply-templates select='node()' />
75 <xsl:template match='xhtml:h2[@id]'>
76 <xsl:variable name='fragment' select='concat("#", @id)' />
78 <xsl:apply-templates select='node()|@*' />
79 <xsl:text> </xsl:text>
80 <small class='permalink'>
81 (<a href='{$fragment}'><xsl:value-of select='$fragment' /></a>)
86 <xsl:template match='copyright'>
88 <xsl:text>Copyright © </xsl:text>
89 <xsl:value-of select='text()' />
90 <xsl:text>.</xsl:text>
94 <xsl:template match='license'>
96 <xsl:text>Copying and distribution of this material</xsl:text>
97 <xsl:if test='normalize-space(modification-allowed)="yes"'>
98 <xsl:text>, with or without modification,</xsl:text>
100 <xsl:text> is permitted under the terms of the </xsl:text>
102 <xsl:attribute name='href'>
103 <xsl:value-of select='normalize-space(uri)' />
105 <xsl:value-of select='name' />
107 <xsl:text>.</xsl:text>
111 <xsl:template match='source'>
113 <xsl:text>This document was compiled from </xsl:text>
114 <a href='{concat($source-uri, revision, ":", file)}'>
115 <xsl:value-of select='file' />
117 <xsl:text> on </xsl:text>
118 <xsl:value-of select='compiletime' />
119 <xsl:text>.</xsl:text>
123 <xsl:template match='/'>
126 <meta name='viewport' content='width=device-width, initial-scale=1' />
127 <link rel='stylesheet' type='text/css' href='/style.css' />
129 <xsl:variable name='page-title' select='string(/document/title)' />
130 <xsl:if test='$page-title and $site-title != $page-title'>
131 <xsl:value-of select='concat($page-title, " – ")' />
133 <xsl:value-of select='$site-title' />
137 <xsl:apply-templates select='/document/xhtml:html/@*' />
138 <xsl:apply-templates select='/document/xhtml:html/node()' />
142 <xsl:apply-templates select='/document/copyright' />
143 <xsl:apply-templates select='/document/license' />
144 <xsl:apply-templates select='/document/source' />