3 ⁌ ⛩️📰 书社 ∷ lib/catalog2transform.xslt
5 © 2023–2024 Lady [@ Lady’s Computer]
7 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
8 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/>.
11 <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
14 xmlns="http://www.w3.org/1999/XSL/Transform"
15 xmlns:html="http://www.w3.org/1999/xhtml"
16 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
17 xmlns:exsl="http://exslt.org/common"
18 xmlns:exslstr="http://exslt.org/strings"
19 xmlns:xlink="http://www.w3.org/1999/xlink"
20 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
21 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
24 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
26 <xslt:transform exclude-result-prefixes="catalog exsl exslstr" version="1.0">
27 <xslt:param name="catalog" select="'catalog'"/>
28 <xslt:variable name="书社:expansion">
29 <xslt:apply-templates select="/" mode="书社:expand"/>
31 <xslt:variable name="书社:result">
32 <xslt:apply-templates select="exsl:node-set($书社:expansion)/*"/>
34 <for-each select="//catalog:uri">
35 <xslt:include href="{@uri}">
36 <if test="contains(@name, ':')">
37 <attribute name="书社:id">
38 <value-of select="@name"/>
43 <xslt:template match="/" priority="1">
45 <xslt:when test="exsl:node-set($书社:result)/*[@书社:disable-output-wrapping]">
46 <xslt:for-each select="exsl:node-set($书社:result)/*">
48 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='disable-output-wrapping')]|node()"/>
53 <xslt:apply-templates select="exsl:node-set($书社:result)" mode="书社:wrap"/>
57 <xslt:template match="/*/*//@书社:disable-output-wrapping" priority="0"/>
58 <xslt:template match="@*|node()" priority="-1">
60 <xslt:apply-templates select="@*|node()"/>
63 <xslt:template match="/*" mode="书社:expand" priority="0">
65 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
66 <xslt:attribute name="itemtype">
67 <xslt:text>&书社;:document</xslt:text>
68 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
69 <xslt:text> </xslt:text>
70 <xslt:value-of select="."/>
73 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
76 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
77 <xslt:variable name="uri" select="substring-before(document($catalog)//catalog:uri[@name=current()/@xlink:href]/@uri[1], '#')"/>
79 <xslt:when test="$uri">
80 <xslt:variable name="expanded">
81 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
83 <xslt:for-each select="exsl:node-set($expanded)/*">
85 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
86 <xslt:attribute name="itemtype">
87 <xslt:text>&书社;:embed</xslt:text>
88 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
89 <xslt:text> </xslt:text>
90 <xslt:value-of select="."/>
93 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
99 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
104 <xslt:template match="@*|text()|*[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
106 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
109 <xslt:template match="text()" mode="书社:metadata"/>
110 <xslt:template match="/" mode="书社:wrap">
111 <xslt:variable name="metadata">
112 <xslt:copy-of select="html/head/*"/>
113 <xslt:apply-templates select="." mode="书社:metadata"/>
114 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:metadata"/>
117 <xslt:copy-of select="html:html/@*"/>
119 <xslt:copy-of select="html:html/html:head/@*"/>
121 <xslt:for-each select="exsl:node-set($metadata)/html:title">
122 <xslt:value-of select="."/>
125 <xslt:copy-of select="exsl:node-set($metadata)/node()[self::comment() or self::* and not(self::html:title)]"/>
126 <xslt:if test="not(exsl:node-set($metadata)/html:meta[@name='generator'])">
127 <html:meta name="generator" content="⛩️📰 书社"/>
131 <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/*"/>
135 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>