]> Lady’s Gitweb - Shushe/blobdiff - lib/expandmetadata.xslt
Support multiple destinations
[Shushe] / lib / expandmetadata.xslt
index f2efd18209177db3a846d1053cf16955ed2a74f8..423924a3d35eb889c8ab4bd46e46a937e6d54c02 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0"?>
 <!--
 <?xml version="1.0"?>
 <!--
-SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
+SPDX-FileCopyrightText: 2023, 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
 SPDX-License-Identifier: MPL-2.0
 -->
 <!--
 ⁌ ⛩📰 书社 ∷ lib/expandmetadata.xslt
 
 SPDX-License-Identifier: MPL-2.0
 -->
 <!--
 ⁌ ⛩📰 书社 ∷ lib/expandmetadata.xslt
 
-© 2023–2024 Lady [@ Ladys Computer].
+© 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/>.
 
 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/>.
@@ -14,13 +14,14 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 <transform
        xmlns="http://www.w3.org/1999/XSL/Transform"
        xmlns:exsl="http://exslt.org/common"
 <transform
        xmlns="http://www.w3.org/1999/XSL/Transform"
        xmlns:exsl="http://exslt.org/common"
+       xmlns:exslstr="http://exslt.org/strings"
        xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
        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:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
        xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
        xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
        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:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
        xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
-       extension-element-prefixes="exsl"
+       extension-element-prefixes="exsl exslstr"
        version="1.0"
 >
        <variable name="builddir" select="//书社vocab:BuildDirectory/@nfo:fileUrl"/>
        version="1.0"
 >
        <variable name="builddir" select="//书社vocab:BuildDirectory/@nfo:fileUrl"/>
@@ -78,37 +79,51 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </otherwise>
                </choose>
        </template>
                        </otherwise>
                </choose>
        </template>
+       <template match="nie:interpretedAs/*" priority="1">
+               <copy>
+                       <apply-templates select="@*|node()"/>
+                       <for-each select="../../书社vocab:hasParsedFileWithMetadata">
+                               <copy-of select="document(@nfo:fileUrl)/书社:parsed/书社:metadata/rdf:RDF/rdf:Description/node()"/>
+                       </for-each>
+               </copy>
+       </template>
        <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
                <copy>
                        <apply-templates select="@*"/>
        <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
                <copy>
                        <apply-templates select="@*"/>
-                       <attribute name="书社vocab:destination">
-                               <value-of select="@书社vocab:path"/>
-                       </attribute>
                        <apply-templates select="node()"/>
                        <apply-templates select="node()"/>
+                       <element name="书社vocab:destination">
+                               <value-of select="@书社vocab:path"/>
+                       </element>
                </copy>
        </template>
        <template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
                <variable name="parsed" select="document(书社vocab:hasParsedFile/@nfo:fileUrl)"/>
                </copy>
        </template>
        <template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
                <variable name="parsed" select="document(书社vocab:hasParsedFile/@nfo:fileUrl)"/>
-               <variable name="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
-               <variable name="destination">
-                       <choose>
-                               <when test="not(contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../'))">
-                                       <value-of select="$parsed/*/@书社:destination"/>
-                               </when>
-                               <otherwise>
-                                       <value-of select="@书社vocab:path"/>
-                               </otherwise>
-                       </choose>
+               <variable name="provided-destinations" select="normalize-space($parsed/*/@书社:destination)"/>
+               <variable name="destinations-fragment">
+                       <if test="$provided-destinations!=''">
+                               <for-each select="exslstr:tokenize($provided-destinations)">
+                                       <element name="书社vocab:destination">
+                                               <value-of select="."/>
+                                       </element>
+                               </for-each>
+                       </if>
                </variable>
                <variable name="dependencies-fragment">
                        <apply-templates select="." mode="书社:dependencies"/>
                </variable>
                <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
                </variable>
                <variable name="dependencies-fragment">
                        <apply-templates select="." mode="书社:dependencies"/>
                </variable>
                <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
+               <variable name="destinations" select="exsl:node-set($destinations-fragment)/node()"/>
+               <variable name="bad-destinations-fragment">
+                       <for-each select="$destinations">
+                               <variable name="destination-delim" select="concat('/', ., '/')"/>
+                               <if test="contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../')">
+                                       <copy-of select="."/>
+                               </if>
+                       </for-each>
+               </variable>
+               <variable name="bad-destinations" select="exsl:node-set($bad-destinations-fragment)/node()"/>
                <copy>
                        <apply-templates select="@*"/>
                <copy>
                        <apply-templates select="@*"/>
-                       <attribute name="书社vocab:destination">
-                               <value-of select="$destination"/>
-                       </attribute>
                        <apply-templates select="node()"/>
                        <for-each select="$dependencies/书社:dependency">
                                <书社vocab:hasDependencyOn rdf:resource="{.}"/>
                        <apply-templates select="node()"/>
                        <for-each select="$dependencies/书社:dependency">
                                <书社vocab:hasDependencyOn rdf:resource="{.}"/>
@@ -116,6 +131,36 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        <for-each select="$dependencies/书社:recursive-dependency">
                                <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
                        </for-each>
                        <for-each select="$dependencies/书社:recursive-dependency">
                                <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
                        </for-each>
+                       <choose>
+                               <when test="not($destinations)">
+                                       <element name="书社vocab:destination">
+                                               <value-of select="@书社vocab:path"/>
+                                       </element>
+                               </when>
+                               <when test="$bad-destinations">
+                                       <message terminate="no">
+                                               <text>Bad destinations: </text>
+                                               <for-each select="$bad-destinations">
+                                                       <if test="position()>1">
+                                                               <text> </text>
+                                                       </if>
+                                                       <text>&lt;</text>
+                                                       <value-of select="."/>
+                                                       <text>></text>
+                                               </for-each>
+                                       </message>
+                                       <element name="书社vocab:destination">
+                                               <value-of select="@书社vocab:path"/>
+                                       </element>
+                               </when>
+                               <otherwise>
+                                       <for-each select="$destinations">
+                                               <element name="书社vocab:destination">
+                                                       <value-of select="."/>
+                                               </element>
+                                       </for-each>
+                               </otherwise>
+                       </choose>
                </copy>
        </template>
        <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
                </copy>
        </template>
        <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
@@ -133,6 +178,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </for-each>
                </copy>
        </template>
                        </for-each>
                </copy>
        </template>
+       <template match="书社vocab:hasParsedFileWithMetadata" priority="1"/>
        <template match="/">
                <variable name="result-fragment">
                        <apply-templates/>
        <template match="/">
                <variable name="result-fragment">
                        <apply-templates/>
@@ -160,7 +206,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        <for-each select="$result//书社vocab:SourceFile">
                                <value-of select="@rdf:about"/>
                                <text>|</text>
                        <for-each select="$result//书社vocab:SourceFile">
                                <value-of select="@rdf:about"/>
                                <text>|</text>
-                               <value-of select="@书社vocab:destination"/>
+                               <for-each select="书社vocab:destination">
+                                       <if test="position()>1">
+                                               <text>;</text>
+                                       </if>
+                                       <value-of select="."/>
+                               </for-each>
                                <text>&#xA;</text>
                        </for-each>
                </exsl:document>
                                <text>&#xA;</text>
                        </for-each>
                </exsl:document>
This page took 0.16217 seconds and 4 git commands to generate.