]> Lady’s Gitweb - Shushe/blobdiff - transforms/expansion.xslt
Move expansion into its own transform
[Shushe] / transforms / expansion.xslt
diff --git a/transforms/expansion.xslt b/transforms/expansion.xslt
new file mode 100644 (file)
index 0000000..8c0dd69
--- /dev/null
@@ -0,0 +1,140 @@
+<?xml version="1.0"?>
+<!--
+SPDX-FileCopyrightText: 2023, 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
+SPDX-License-Identifier: MPL-2.0
+-->
+<!--
+⁌ ⛩📰 书社 ∷ transforms/expansion.xslt
+
+© 2023–2025 Lady [@ Ladys Computer].
+
+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:exsl="http://exslt.org/common"
+       xmlns:exslstr="http://exslt.org/strings"
+       xmlns:html="http://www.w3.org/1999/xhtml"
+       xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
+       xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+       xmlns:xlink="http://www.w3.org/1999/xlink"
+       xmlns:书社="&书社;"
+       xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
+       exclude-result-prefixes="nfo 书社vocab"
+       extension-element-prefixes="exsl exslstr"
+       version="1.0"
+>
+       <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:expansion.xslt</书社:id>
+       <template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
+               <variable name="link" select="."/>
+               <variable name="identifier" select="string(@xlink:href)"/>
+               <variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
+               <variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
+               <choose>
+                       <when test="$included">
+                               <for-each select="$included">
+                                       <sort select="@rdf:about" data-type="text" lang="zxx" case-order="upper-first"/>
+                                       <variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
+                                       <variable name="expanded">
+                                               <apply-templates select="document($uri)" mode="书社:expand">
+                                                       <with-param name="identifier" select="string(@rdf:about)"/>
+                                               </apply-templates>
+                                       </variable>
+                                       <for-each select="exsl:node-set($expanded)/node()">
+                                               <copy>
+                                                       <choose>
+                                                               <when test="self::html:*">
+                                                                       <variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
+                                                                       <attribute name="itemscope">itemscope</attribute>
+                                                                       <attribute name="itemtype">
+                                                                               <for-each select="$existing-types/token[string()!='&书社;:document']">
+                                                                                       <if test="position()!=1">
+                                                                                               <text> </text>
+                                                                                       </if>
+                                                                                       <value-of select="."/>
+                                                                               </for-each>
+                                                                               <if test="not($existing-types/token[string()='&书社;:embed'])">
+                                                                                       <if test="$existing-types/token[string()!='&书社;:document']">
+                                                                                               <text> </text>
+                                                                                       </if>
+                                                                                       <text>&书社;:embed</text>
+                                                                               </if>
+                                                                       </attribute>
+                                                                       <choose>
+                                                                               <when test="$link/@书社:archived-as">
+                                                                                       <copy-of select="$link/@书社:archived-as"/>
+                                                                               </when>
+                                                                               <when test="@书社:archived-as">
+                                                                                       <copy-of select="@书社:archived-as"/>
+                                                                               </when>
+                                                                       </choose>
+                                                                       <copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
+                                                               </when>
+                                                               <otherwise>
+                                                                       <choose>
+                                                                               <when test="self::* and $link/@书社:archived-as">
+                                                                                       <copy-of select="$link/@书社:archived-as"/>
+                                                                               </when>
+                                                                               <when test="@书社:archived-as">
+                                                                                       <copy-of select="@书社:archived-as"/>
+                                                                               </when>
+                                                                       </choose>
+                                                                       <copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
+                                                               </otherwise>
+                                                       </choose>
+                                               </copy>
+                                       </for-each>
+                               </for-each>
+                       </when>
+                       <otherwise>
+                               <copy>
+                                       <apply-templates select="@*|node()" mode="书社:expand"/>
+                               </copy>
+                       </otherwise>
+               </choose>
+       </template>
+       <template match="/node()" mode="书社:expand" priority="0">
+               <param name="identifier" select="$IDENTIFIER"/>
+               <copy>
+                       <if test="self::*">
+                               <attribute name="书社:cksum">
+                                       <value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
+                               </attribute>
+                               <attribute name="书社:identifier">
+                                       <value-of select="$identifier"/>
+                               </attribute>
+                               <attribute name="书社:mtime">
+                                       <value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:fileLastModified"/>
+                               </attribute>
+                       </if>
+                       <choose>
+                               <when test="self::html:*">
+                                       <variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
+                                       <attribute name="itemscope">itemscope</attribute>
+                                       <attribute name="itemtype">
+                                               <for-each select="$existing-types/token">
+                                                       <if test="position()!=1">
+                                                               <text> </text>
+                                                       </if>
+                                                       <value-of select="."/>
+                                               </for-each>
+                                               <if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
+                                                       <if test="$existing-types/token">
+                                                               <text> </text>
+                                                       </if>
+                                                       <text>&书社;:document</text>
+                                               </if>
+                                       </attribute>
+                                       <apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype') or namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
+                               </when>
+                               <otherwise>
+                                       <apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
+                               </otherwise>
+                       </choose>
+               </copy>
+       </template>
+</transform>
This page took 0.25739 seconds and 4 git commands to generate.