2 This is an extremely simple XSLT transform which simply reads in a
5 • Replaces the `<html:shrine-content>` element with the content of the document it is being applied to,
7 • If the root element of the document it is being applied to has a `@data-shrine-header` attribute, replaces the `<html:shrine-header>` with the contents of the corresponding header file (`⸺-header.xml`), and
9 • If the root element of the document it is being applied to has a `@data-shrine-footer` attribute, replaces the `<html:shrine-footer>` with the contents of the corresponding footer file (`⸺-footer.xml`), and
11 • Copies any remaining `@lang` or `@data-*` attributes from the root element of the document it is being applied to over to the root element of the template.
13 The intent is that this file is used in conjunction with a Makefile to quickly automate inserting header and footer content into documents.
14 The exact feature·set might be somewhat more expansive than the description above; for a lengthier overview of what this file does, see `README.markdown`.
16 Feel free to add additional templates and features to suit your needs!
20 © 2022 Lady [@ Lady’s Computer]
22 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
23 If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
26 xmlns:html="http://www.w3.org/1999/xhtml"
27 xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
30 <xslt:variable name="source" select="current()"/>
31 <xslt:variable name="template" select="document('./template.xml')"/>
34 Instead of actually processing the root node, process the template in `template` mode.
36 <xslt:template match="/">
37 <xslt:apply-templates select="$template" mode="template"/>
41 Process non‐template elements.
42 By default, just copy the element, but remove any `@data-shrine-*` attribuets or `@slot` attributes with a value that begins with `shrine-`.
43 Some elements may have special treatment.
45 <xslt:template match="*" mode="content">
46 <xslt:element name="{local-name()}">
47 <xslt:for-each select="@*[not(starts-with(name(), 'data-shrine-')) and not(name()='slot' and starts-with(., 'shrine-'))]">
50 <xslt:for-each select="*|text()">
52 <xslt:when test="@slot[starts-with(., 'shrine-')]">
54 <text> placeholder for slotted element </text>
58 <xslt:apply-templates select="." mode="content"/>
66 Process text content; just make a copy.
68 <xslt:template match="text()" mode="content">
73 Process template elements.
74 By default, just copy the element.
75 This behaviour will be overridden for certain elements to insert the page content.
77 <xslt:template match="*" mode="template">
78 <xslt:element name="{local-name()}">
79 <xslt:for-each select="@*">
82 <xslt:apply-templates mode="template"/>
87 Process template text; just make a copy.
89 <xslt:template match="text()" mode="content">
94 Process the template `<html>` elements.
95 This copies over `@lang` and non‐shrine `@data-*` attributes from the root node.
97 <xslt:template match="html:html" mode="template">
99 <xslt:for-each select="@*[not(starts-with(name(), 'xmlns'))]">
102 <xslt:for-each select="$source/*/@*[name()='lang' or starts-with(name(), 'data-') and not(starts-with(name(), 'data-shrine-'))]">
103 <xslt:if test="not($template/*/@*[name()=name(current())])">
107 <xslt:apply-templates mode="template"/>
112 Process the template `<head>` elements.
113 This inserts appropriate metadata based on the document.
115 <xslt:template match="html:head" mode="template">
117 <xslt:for-each select="@*">
120 <xslt:if test="not($source//html:title[@slot='shrine-head'])">
122 <xslt:apply-templates select="$source//html:h1" mode="text"/>
125 <xslt:apply-templates mode="template"/>
126 <xslt:for-each select="$source//*[@slot='shrine-head']">
127 <xslt:apply-templates select="." mode="content"/>
133 Process the template header.
134 Read the `@data-header` attribute of the root element, append `"-header.xml"` to the end of it, and process the resulting document.
135 If no `@data-header` attribute is provided, no header is rendered.
137 <xslt:template match="html:shrine-header" mode="template">
138 <xslt:for-each select="$source/*/@data-shrine-header">
139 <xslt:apply-templates select="document(concat('./', ., '-header.xml'), $template)/*" mode="content"/>
144 Process the template footer.
145 Read the `@data-footer` attribute of the root element, append `"-footer.xml"` to the end of it, and process the resulting document.
146 If no `@data-footer` attribute is provided, no footer is rendered.
148 <xslt:template match="html:shrine-footer" mode="template">
149 <xslt:for-each select="$source/*/@data-shrine-footer">
150 <xslt:apply-templates select="document(concat('./', ., '-footer.xml'), $template)/*" mode="content"/>
157 <xslt:template match="html:shrine-content" mode="template">
158 <xslt:apply-templates select="$source/*" mode="content"/>
162 Provide the complete text content of the provided element.
164 <xslt:template match="*|text()" mode="text">
166 <xslt:when test="self::*">
167 <xslt:apply-templates mode="text"/>
169 <xslt:when test="self::text()">
176 Set the output mode to HTML.
178 <xslt:output method="html" charset="UTF-8" doctype-system="about:legacy-compat" indent="no"/>