]> Lady’s Gitweb - Shrine-XSLT/blobdiff - transform.xslt
Change output mode to H·T·M·L
[Shrine-XSLT] / transform.xslt
index 2e3c7bd3e45f51b41d7dcfe128ac3e7354d2b74e..0919121f56192ea1934cd58726d8f19c7db478df 100644 (file)
@@ -23,8 +23,6 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v.
 If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
 -->
 <xslt:transform
-       xmlns="http://www.w3.org/1999/xhtml"
-       xmlns:exslt="http://exslt.org/common"
        xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns:xslt="http://www.w3.org/1999/XSL/Transform"
        version="1.0"
@@ -36,7 +34,7 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                Instead of actually processing the root node, process the template in `template` mode.
        -->
        <xslt:template match="/">
-               <xslt:apply-templates select="exslt:node-set($template)" mode="template"/>
+               <xslt:apply-templates select="$template" mode="template"/>
        </xslt:template>
 
        <!--
@@ -44,8 +42,8 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                By default, just copy the element, but remove any `@data-shrine-*` attribuets or `@slot` attributes with a value that begins with `shrine-`.
                Some elements may have special treatment.
        -->
-       <xslt:template match="*|text()" mode="content">
-               <xslt:copy>
+       <xslt:template match="*" mode="content">
+               <xslt:element name="{local-name()}">
                        <xslt:for-each select="@*[not(starts-with(name(), 'data-shrine-')) and not(name()='slot' and starts-with(., 'shrine-'))]">
                                <xslt:copy/>
                        </xslt:for-each>
@@ -61,7 +59,14 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                                        </xslt:otherwise>
                                </xslt:choose>
                        </xslt:for-each>
-               </xslt:copy>
+               </xslt:element>
+       </xslt:template>
+
+       <!--
+               Process text content; just make a copy.
+       -->
+       <xslt:template match="text()" mode="content">
+               <xslt:copy/>
        </xslt:template>
 
        <!--
@@ -69,13 +74,20 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                By default, just copy the element.
                This behaviour will be overridden for certain elements to insert the page content.
        -->
-       <xslt:template match="*|text()" mode="template">
-               <xslt:copy>
+       <xslt:template match="*" mode="template">
+               <xslt:element name="{local-name()}">
                        <xslt:for-each select="@*">
                                <xslt:copy/>
                        </xslt:for-each>
                        <xslt:apply-templates mode="template"/>
-               </xslt:copy>
+               </xslt:element>
+       </xslt:template>
+
+       <!--
+               Process template text; just make a copy.
+       -->
+       <xslt:template match="text()" mode="content">
+               <xslt:copy/>
        </xslt:template>
 
        <!--
@@ -83,17 +95,17 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                This copies over `@lang` and non‐shrine `@data-*` attributes from the root node.
        -->
        <xslt:template match="html:html" mode="template">
-               <xslt:copy>
-                       <xslt:for-each select="@*">
+               <html>
+                       <xslt:for-each select="@*[not(starts-with(name(), 'xmlns'))]">
                                <xslt:copy/>
                        </xslt:for-each>
-                       <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-'))]">
-                               <xslt:if test="not(exslt:node-set($template)/*/@*[name()=name(current())])">
+                       <xslt:for-each select="$source/*/@*[name()='lang' or starts-with(name(), 'data-') and not(starts-with(name(), 'data-shrine-'))]">
+                               <xslt:if test="not($template/*/@*[name()=name(current())])">
                                        <xslt:copy/>
                                </xslt:if>
                        </xslt:for-each>
                        <xslt:apply-templates mode="template"/>
-               </xslt:copy>
+               </html>
        </xslt:template>
 
        <!--
@@ -101,22 +113,20 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                This inserts appropriate metadata based on the document.
        -->
        <xslt:template match="html:head" mode="template">
-               <xslt:copy>
+               <head>
                        <xslt:for-each select="@*">
                                <xslt:copy/>
                        </xslt:for-each>
-                       <xslt:if test="not(exslt:node-set($source)//html:title[@slot='shrine-head'])">
-                               <xslt:text>&#x0A;</xslt:text>
+                       <xslt:if test="not($source//html:title[@slot='shrine-head'])">
                                <title>
-                                       <xslt:apply-templates select="exslt:node-set($source)//html:h1" mode="text"/>
+                                       <xslt:apply-templates select="$source//html:h1" mode="text"/>
                                </title>
                        </xslt:if>
                        <xslt:apply-templates mode="template"/>
-                       <xslt:for-each select="exslt:node-set($source)//*[@slot='shrine-head']">
-                               <xslt:text>&#x0A;</xslt:text>
+                       <xslt:for-each select="$source//*[@slot='shrine-head']">
                                <xslt:apply-templates select="." mode="content"/>
                        </xslt:for-each>
-               </xslt:copy>
+               </head>
        </xslt:template>
 
        <!--
@@ -125,7 +135,7 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                If no `@data-header` attribute is provided, no header is rendered.
        -->
        <xslt:template match="html:shrine-header" mode="template">
-               <xslt:for-each select="exslt:node-set($source)/*/@data-shrine-header">
+               <xslt:for-each select="$source/*/@data-shrine-header">
                        <xslt:apply-templates select="document(concat('./', ., '-header.xml'), $template)/*" mode="content"/>
                </xslt:for-each>
        </xslt:template>
@@ -136,7 +146,7 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                If no `@data-footer` attribute is provided, no footer is rendered.
        -->
        <xslt:template match="html:shrine-footer" mode="template">
-               <xslt:for-each select="exslt:node-set($source)/*/@data-shrine-footer">
+               <xslt:for-each select="$source/*/@data-shrine-footer">
                        <xslt:apply-templates select="document(concat('./', ., '-footer.xml'), $template)/*" mode="content"/>
                </xslt:for-each>
        </xslt:template>
@@ -145,7 +155,7 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                Process the content.
        -->
        <xslt:template match="html:shrine-content" mode="template">
-               <xslt:apply-templates select="exslt:node-set($source)/*" mode="content"/>
+               <xslt:apply-templates select="$source/*" mode="content"/>
        </xslt:template>
 
        <!--
@@ -161,4 +171,9 @@ If a copy of the MPL was not distributed with this file, You can obtain one at h
                        </xslt:when>
                </xslt:choose>
        </xslt:template>
+
+       <!--
+               Set the output mode to HTML.
+       -->
+       <xslt:output method="html" charset="UTF-8" doctype-system="about:legacy-compat" indent="no"/>
 </xslt:transform>
This page took 0.054215 seconds and 4 git commands to generate.