]> Lady’s Gitweb - Shushe/blob - lib/catalog2transform.xslt
Automatically encapsulate metadata and preserve it
[Shushe] / lib / catalog2transform.xslt
1 <?xml version="1.0"?>
2 <!--
3 ⁌ ⛩️📰 书社 ∷ lib/catalog2transform.xslt
4
5 © 2023–2024 Lady [@ Lady’s Computer]
6
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/>.
9 -->
10 <transform
11 xmlns="http://www.w3.org/1999/XSL/Transform"
12 xmlns:html="http://www.w3.org/1999/xhtml"
13 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
14 xmlns:exsl="http://exslt.org/common"
15 xmlns:exslstr="http://exslt.org/strings"
16 xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
18 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
19 version="1.0"
20 >
21 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
22 <template match="/">
23 <xslt:transform exclude-result-prefixes="catalog exsl" version="1.0">
24 <xslt:param name="catalog" select="'catalog'"/>
25 <xslt:variable name="书社:expansion">
26 <xslt:apply-templates select="/" mode="书社:expand"/>
27 </xslt:variable>
28 <xslt:variable name="书社:result">
29 <xslt:apply-templates select="exsl:node-set($书社:expansion)/*"/>
30 </xslt:variable>
31 <for-each select="//catalog:uri">
32 <xslt:include href="{@uri}">
33 <if test="contains(@name, ':')">
34 <attribute name="书社:id">
35 <value-of select="@name"/>
36 </attribute>
37 </if>
38 </xslt:include>
39 </for-each>
40 <xslt:template match="/" priority="1">
41 <xslt:variable name="metadata">
42 <xslt:copy-of select="exsl:node-set($书社:result)/html/head/*"/>
43 <xslt:apply-templates select="exsl:node-set($书社:result)" mode="书社:metadata"/>
44 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:metadata"/>
45 </xslt:variable>
46 <html:html>
47 <xslt:copy-of select="exsl:node-set($书社:result)/html:html/@*"/>
48 <html:head>
49 <xslt:copy-of select="exsl:node-set($书社:result)/html:html/html:head/@*"/>
50 <html:title>
51 <xslt:for-each select="exsl:node-set($metadata)/html:title">
52 <xslt:value-of select="."/>
53 </xslt:for-each>
54 </html:title>
55 <xslt:copy-of select="exsl:node-set($metadata)/node()[self::comment() or self::* and not(self::html:title)]"/>
56 <xslt:if test="not(exsl:node-set($metadata)/html:meta[@name='generator'])">
57 <html:meta name="generator" content="⛩️📰 书社"/>
58 </xslt:if>
59 </html:head>
60 <html:body>
61 <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/*"/>
62 </html:body>
63 </html:html>
64 </xslt:template>
65 <xslt:template match="@*|node()" priority="-1">
66 <xslt:copy>
67 <xslt:apply-templates select="@*|node()"/>
68 </xslt:copy>
69 </xslt:template>
70 <xslt:template match="/*" mode="书社:expand" priority="0">
71 <xslt:copy>
72 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
73 <xslt:attribute name="itemtype">
74 <xslt:text>urn:fdc:ladys.computer:20231231:Shu1She4:document</xslt:text>
75 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
76 <xslt:text> </xslt:text>
77 <xslt:value-of select="."/>
78 </xslt:for-each>
79 </xslt:attribute>
80 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
81 </xslt:copy>
82 </xslt:template>
83 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
84 <xslt:variable name="uri" select="substring-before(document($catalog)//catalog:uri[@name=current()/@xlink:href]/@uri[1], '#')"/>
85 <xslt:choose>
86 <xslt:when test="$uri">
87 <xslt:variable name="expanded">
88 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
89 </xslt:variable>
90 <xslt:for-each select="exsl:node-set($expanded)/*">
91 <xslt:copy>
92 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
93 <xslt:attribute name="itemtype">
94 <xslt:text>urn:fdc:ladys.computer:20231231:Shu1She4:embed</xslt:text>
95 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='urn:fdc:ladys.computer:20231231:Shu1She4:document']">
96 <xslt:text> </xslt:text>
97 <xslt:value-of select="."/>
98 </xslt:for-each>
99 </xslt:attribute>
100 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
101 </xslt:copy>
102 </xslt:for-each>
103 </xslt:when>
104 <xslt:otherwise>
105 <xslt:copy>
106 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
107 </xslt:copy>
108 </xslt:otherwise>
109 </xslt:choose>
110 </xslt:template>
111 <xslt:template match="@*|text()|*[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
112 <xslt:copy>
113 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
114 </xslt:copy>
115 </xslt:template>
116 <xslt:template match="text()" mode="书社:metadata"/>
117 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>
118 </xslt:transform>
119 </template>
120 </transform>
This page took 0.057033 seconds and 5 git commands to generate.