]> Lady’s Gitweb - Shushe/commitdiff
Allow output wrapping to be disabled
authorLady <redacted>
Mon, 1 Jan 2024 18:22:23 +0000 (13:22 -0500)
committerLady <redacted>
Tue, 2 Jan 2024 18:26:46 +0000 (13:26 -0500)
This also extracts wrapping out into a separate mode, `书社:wrap`,
enabling it to be overridden by transforms if necessary.

README.markdown
lib/catalog2transform.xslt

index 2bb1bcea0e82631c09c3f6249b5eaa635f27beac..681e8c4acb2940d25bbf528cf62b013c5fe093ca 100644 (file)
@@ -351,6 +351,10 @@ This mechanism can be used to allow transforms to insert content
 </transform>
 ```
 
+Output wrapping can be entirely disabled by adding a
+  `@书社:disable-output-wrapping` attribute to the top‐level element in
+  the result tree.
+
 ## License
 
 Source files are licensed under the terms of the <cite>Mozilla Public
index 08918b2a3cae6bc91f0b4a73f0dc2338f2174d5a..6044a136901c64b2d7775429fbbcb18a4052fb78 100644 (file)
@@ -7,6 +7,9 @@
 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
 If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 -->
+<!DOCTYPE transform [
+       <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
+]>
 <transform
        xmlns="http://www.w3.org/1999/XSL/Transform"
        xmlns:html="http://www.w3.org/1999/xhtml"
@@ -20,7 +23,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 >
        <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
        <template match="/">
-               <xslt:transform exclude-result-prefixes="catalog exsl" version="1.0">
+               <xslt:transform exclude-result-prefixes="catalog exsl exslstr" version="1.0">
                        <xslt:param name="catalog" select="'catalog'"/>
                        <xslt:variable name="书社:expansion">
                                <xslt:apply-templates select="/" mode="书社:expand"/>
@@ -38,30 +41,20 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                </xslt:include>
                        </for-each>
                        <xslt:template match="/" priority="1">
-                               <xslt:variable name="metadata">
-                                       <xslt:copy-of select="exsl:node-set($书社:result)/html/head/*"/>
-                                       <xslt:apply-templates select="exsl:node-set($书社:result)" mode="书社:metadata"/>
-                                       <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:metadata"/>
-                               </xslt:variable>
-                               <html:html>
-                                       <xslt:copy-of select="exsl:node-set($书社:result)/html:html/@*"/>
-                                       <html:head>
-                                               <xslt:copy-of select="exsl:node-set($书社:result)/html:html/html:head/@*"/>
-                                               <html:title>
-                                                       <xslt:for-each select="exsl:node-set($metadata)/html:title">
-                                                               <xslt:value-of select="."/>
-                                                       </xslt:for-each>
-                                               </html:title>
-                                               <xslt:copy-of select="exsl:node-set($metadata)/node()[self::comment() or self::* and not(self::html:title)]"/>
-                                               <xslt:if test="not(exsl:node-set($metadata)/html:meta[@name='generator'])">
-                                                       <html:meta name="generator" content="⛩️📰 书社"/>
-                                               </xslt:if>
-                                       </html:head>
-                                       <html:body>
-                                               <xslt:copy-of select="exsl:node-set($书社:result)/*[not(self::html:html or self::html:body)]|exsl:node-set($书社:result)/html:html/*[not(self::html:head or self::html:body)]|exsl:node-set($书社:result)/html:html/html:body/*|exsl:node-set($书社:result)/html:body/*"/>
-                                       </html:body>
-                               </html:html>
+                               <xslt:choose>
+                                       <xslt:when test="exsl:node-set($书社:result)/*[@书社:disable-output-wrapping]">
+                                               <xslt:for-each select="exsl:node-set($书社:result)/*">
+                                                       <xslt:copy>
+                                                               <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='disable-output-wrapping')]|node()"/>
+                                                       </xslt:copy>
+                                               </xslt:for-each>
+                                       </xslt:when>
+                                       <xslt:otherwise>
+                                               <xslt:apply-templates select="exsl:node-set($书社:result)" mode="书社:wrap"/>
+                                       </xslt:otherwise>
+                               </xslt:choose>
                        </xslt:template>
+                       <xslt:template match="/*/*//@书社:disable-output-wrapping" priority="0"/>
                        <xslt:template match="@*|node()" priority="-1">
                                <xslt:copy>
                                        <xslt:apply-templates select="@*|node()"/>
@@ -71,7 +64,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <xslt:copy>
                                        <xslt:attribute name="itemscope">itemscope</xslt:attribute>
                                        <xslt:attribute name="itemtype">
-                                               <xslt:text>urn:fdc:ladys.computer:20231231:Shu1She4:document</xslt:text>
+                                               <xslt:text>&书社;:document</xslt:text>
                                                <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
                                                        <xslt:text> </xslt:text>
                                                        <xslt:value-of select="."/>
@@ -91,8 +84,8 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                        <xslt:copy>
                                                                <xslt:attribute name="itemscope">itemscope</xslt:attribute>
                                                                <xslt:attribute name="itemtype">
-                                                                       <xslt:text>urn:fdc:ladys.computer:20231231:Shu1She4:embed</xslt:text>
-                                                                       <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='urn:fdc:ladys.computer:20231231:Shu1She4:document']">
+                                                                       <xslt:text>&书社;:embed</xslt:text>
+                                                                       <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
                                                                                <xslt:text> </xslt:text>
                                                                                <xslt:value-of select="."/>
                                                                        </xslt:for-each>
@@ -114,6 +107,31 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                </xslt:copy>
                        </xslt:template>
                        <xslt:template match="text()" mode="书社:metadata"/>
+                       <xslt:template match="/" mode="书社:wrap">
+                               <xslt:variable name="metadata">
+                                       <xslt:copy-of select="html/head/*"/>
+                                       <xslt:apply-templates select="." mode="书社:metadata"/>
+                                       <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:metadata"/>
+                               </xslt:variable>
+                               <html:html>
+                                       <xslt:copy-of select="html:html/@*"/>
+                                       <html:head>
+                                               <xslt:copy-of select="html:html/html:head/@*"/>
+                                               <html:title>
+                                                       <xslt:for-each select="exsl:node-set($metadata)/html:title">
+                                                               <xslt:value-of select="."/>
+                                                       </xslt:for-each>
+                                               </html:title>
+                                               <xslt:copy-of select="exsl:node-set($metadata)/node()[self::comment() or self::* and not(self::html:title)]"/>
+                                               <xslt:if test="not(exsl:node-set($metadata)/html:meta[@name='generator'])">
+                                                       <html:meta name="generator" content="⛩️📰 书社"/>
+                                               </xslt:if>
+                                       </html:head>
+                                       <html:body>
+                                               <xslt:copy-of select="*[not(self::html:html or self::html:body)]|html:html/*[not(self::html:head or self::html:body)]|html:html/html:body/*|html:body/*"/>
+                                       </html:body>
+                               </html:html>
+                       </xslt:template>
                        <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>
                </xslt:transform>
        </template>
This page took 0.032683 seconds and 4 git commands to generate.