]> Lady’s Gitweb - Shushe/commitdiff
Improve <书社:apply-attributes>, @书社:archived-as
authorLady <redacted>
Tue, 20 Aug 2024 06:22:17 +0000 (02:22 -0400)
committerLady <redacted>
Thu, 22 Aug 2024 01:39:11 +0000 (21:39 -0400)
- `<书社:apply-attributes>` should not prevent H·T·M·L from wrapping.
  Note that the H·T·M·L wrapper is still not
  `<书社:apply-attributes>`‐aware; it will _not_ seek into the wrapped
  contents to search for attributes to pull upwards to the root
  element. This could probably be improved.

- `@书社:archived-as` can now be applied to `<书社:link>` and will be
  passed down to any embedded contents.

- `@书社:archived-as` will not be deleted during attribute application
  onto the root element; it now ensures there is a nonroot, nonarchive
  ancestor. This is required because archive children are processed
  into a separate document prior to application.

  An alternative approach might be to wrap archive children in a
  `<书社:archive>` element before application and then strip it after,
  but this is a fair bit of added work for little benefit. It’s a fair
  question whether removing invalid `@书社:*` attributes like this is
  even a good practice—invalid `<书社:link>` elements are maintained,
  in contrast.

lib/catalog2transform.xslt

index 05ca7d52627e49520589f477ea447b9955bbcbe2..2c555e32c189c0ade8b54990a7ed439910f40b46 100644 (file)
@@ -143,7 +143,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                        <xslt:choose>
                                                                                <xslt:when test="@namespace-uri='&xml;'"/>
                                                                                <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
-                                                                               <xslt:when test="@namespace-uri='&书社;' and @local-name='archived-as' and not($context-nodes/ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)][1][self::书社:archive])"/>
+                                                                               <xslt:when test="@namespace-uri='&书社;' and @local-name='archived-as' and $context-nodes/ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)][position()=1 and not(self::书社:archive)]"/>
                                                                                <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
                                                                                <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
                                                                                <xslt:otherwise>
@@ -262,10 +262,11 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                </html:html>
                        </xslt:template>
                        <xslt:template match="/" priority="1">
-                               <xslt:variable name="result-nodes" select="$书社:result/node()[not(self::书社:apply-attributes-to-root)]|$书社:result/书社:apply-attributes-to-root/descendant::node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
+                               <xslt:variable name="result-nodes" select="$书社:result/node()[not(self::书社:apply-attributes-to-root)]|$书社:result/书社:apply-attributes-to-root//node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
+                               <xslt:variable name="significant-nodes" select="$result-nodes/descendant-or-self::*[not(self::书社:apply-attributes) and not(ancestor::*[not(self::书社:apply-attributes)])]"/>
                                <xslt:variable name="root-with-attributes">
                                        <xslt:choose>
-                                               <xslt:when test="not($result-nodes/self::html:*) or $result-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $result-nodes/@书社:disable-output-wrapping or $书社:result//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
+                                               <xslt:when test="not($significant-nodes/self::html:*) or $significant-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $significant-nodes/@书社:disable-output-wrapping or $书社:result//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
                                                        <xslt:call-template name="书社:apply-attributes">
                                                                <xslt:with-param name="and-version" select="true()"/>
                                                                <xslt:with-param name="context-nodes" select="$书社:result//书社:apply-attributes-to-root"/>
@@ -343,13 +344,15 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </xslt:variable>
                                                                <xslt:variable name="wrapped-component-fragment">
                                                                        <xslt:for-each select="exsl:node-set($component-fragment)/*">
+                                                                               <xslt:variable name="result-nodes" select="self::*[not(self::书社:apply-attributes-to-root)]|self::书社:apply-attributes-to-root//node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
+                                                                               <xslt:variable name="significant-nodes" select="$result-nodes/descendant-or-self::*[not(self::书社:apply-attributes) and not(ancestor::*[not(self::书社:apply-attributes)])]"/>
                                                                                <xslt:choose>
-                                                                                       <xslt:when test="self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|@书社:disable-output-wrapping">
+                                                                                       <xslt:when test="not($significant-nodes/self::html:*) or $significant-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $significant-nodes/@书社:disable-output-wrapping">
                                                                                                <xslt:copy-of select="."/>
                                                                                        </xslt:when>
                                                                                        <xslt:otherwise>
                                                                                                <xslt:call-template name="书社:wrap">
-                                                                                                       <xslt:with-param name="nodes" select="."/>
+                                                                                                       <xslt:with-param name="nodes" select="$result-nodes"/>
                                                                                                </xslt:call-template>
                                                                                        </xslt:otherwise>
                                                                                </xslt:choose>
@@ -382,6 +385,7 @@ 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="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
+                               <xslt:variable name="link" select="."/>
                                <xslt:variable name="identifier" select="string(@xlink:href)"/>
                                <xslt:variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
                                <xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
@@ -421,10 +425,26 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                                                        </xslt:text>
                                                                                                </xslt:if>
                                                                                        </xslt:attribute>
-                                                                                       <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
+                                                                                       <xslt:choose>
+                                                                                               <xslt:when test="$link/@书社:archived-as">
+                                                                                                       <xslt:copy-of select="$link/@书社:archived-as"/>
+                                                                                               </xslt:when>
+                                                                                               <xslt:when test="@书社:archived-as">
+                                                                                                       <xslt:copy-of select="@书社:archived-as"/>
+                                                                                               </xslt:when>
+                                                                                       </xslt:choose>
+                                                                                       <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
                                                                                </xslt:when>
                                                                                <xslt:otherwise>
-                                                                                       <xslt:copy-of select="@*|node()"/>
+                                                                                       <xslt:choose>
+                                                                                               <xslt:when test="self::* and $link/@书社:archived-as">
+                                                                                                       <xslt:copy-of select="$link/@书社:archived-as"/>
+                                                                                               </xslt:when>
+                                                                                               <xslt:when test="@书社:archived-as">
+                                                                                                       <xslt:copy-of select="@书社:archived-as"/>
+                                                                                               </xslt:when>
+                                                                                       </xslt:choose>
+                                                                                       <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
                                                                                </xslt:otherwise>
                                                                        </xslt:choose>
                                                                </xslt:copy>
This page took 0.034881 seconds and 4 git commands to generate.