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="http://www.w3.org/1999/xhtml"
27 xmlns:exslt="http://exslt.org/common"
28 xmlns:html="http://www.w3.org/1999/xhtml"
29 xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
32 <xslt:variable name="source" select="current()"/>
33 <xslt:variable name="template" select="document('./template.xml')"/>
36 Instead of actually processing the root node, process the template in `template` mode.
38 <xslt:template match="/">
39 <xslt:apply-templates select="exslt:node-set($template)" mode="template"/>
43 Process non‐template elements.
44 By default, just copy the element, but remove any `@data-shrine-*` attribuets or `@slot` attributes with a value that begins with `shrine-`.
46 <xslt:template match="*|text()" mode="content">
48 <xslt:for-each select="@*[not(starts-with(name(), 'data-shrine-')) and not(name()='slot' and starts-with(., 'shrine-'))]">
51 <xslt:for-each select="*|text()">
53 <xslt:when test="@slot[starts-with(., 'shrine-')]">
55 <text> placeholder for slotted element </text>
59 <xslt:apply-templates select="." mode="content"/>
67 Process template elements.
68 By default, just copy the element.
69 This behaviour will be overridden for certain elements to insert the page content.
71 <xslt:template match="*|text()" mode="template">
73 <xslt:for-each select="@*">
76 <xslt:apply-templates mode="template"/>
81 Process the template `<html>`.
82 This copies over `@lang` and non‐shrine `@data-*` attributes from the root node.
84 <xslt:template match="html:html" mode="template">
86 <xslt:for-each select="@*">
89 <xslt:for-each select="exslt:node-set($source)/*/@*[name()='lang' or name()='xml:lang' or starts-with(name(), 'data-') and not(starts-with(name(), 'data-shrine-'))]">
90 <xslt:if test="not(exslt:node-set($template)/*/@*[name()=name(current())])">
94 <xslt:apply-templates mode="template"/>
99 Process the template `<head>`.
100 This inserts appropriate metadata based on the document.
102 <xslt:template match="html:head" mode="template">
104 <xslt:for-each select="@*">
107 <xslt:for-each select="exslt:node-set($source)//*[@slot='shrine-head']">
108 <xslt:text>
</xslt:text>
109 <xslt:apply-templates select="." mode="content"/>
111 <xslt:if test="not(exslt:node-set($source)//html:title[@slot='shrine-head'])">
112 <xslt:text>
</xslt:text>
114 <xslt:apply-templates select="exslt:node-set($source)//html:h1" mode="text"/>
117 <xslt:apply-templates mode="template"/>
122 Process the template header.
123 Read the `@data-header` attribute of the root element, append `"-header.xml"` to the end of it, and process the resulting document.
124 If no `@data-header` attribute is provided, no header is rendered.
126 <xslt:template match="html:shrine-header" mode="template">
127 <xslt:for-each select="exslt:node-set($source)/*/@data-shrine-header">
128 <xslt:apply-templates select="document(concat('./', ., '-header.xml'), $template)/*" mode="content"/>
133 Process the template footer.
134 Read the `@data-footer` attribute of the root element, append `"-footer.xml"` to the end of it, and process the resulting document.
135 If no `@data-footer` attribute is provided, no footer is rendered.
137 <xslt:template match="html:shrine-footer" mode="template">
138 <xslt:for-each select="exslt:node-set($source)/*/@data-shrine-footer">
139 <xslt:apply-templates select="document(concat('./', ., '-footer.xml'), $template)/*" mode="content"/>
146 <xslt:template match="html:shrine-content" mode="template">
147 <xslt:apply-templates select="exslt:node-set($source)/*" mode="content"/>
151 Provide the complete text content of the provided element.
153 <xslt:template match="*|text()" mode="text">
155 <xslt:when test="self::*">
156 <xslt:apply-templates mode="text"/>
158 <xslt:when test="self::text()">