]> Lady’s Gitweb - Shushe/commitdiff
Add <书社:apply-attributes> transformation
authorLady <redacted>
Sat, 6 Jan 2024 03:59:15 +0000 (22:59 -0500)
committerLady <redacted>
Sat, 6 Jan 2024 05:03:49 +0000 (00:03 -0500)
The behaviour of `transforms/asset.xslt` is useful, but limited in that
the H·T·M·L elements it creates don’t have any attributes beyond
`@src`. `<书社:apply-attributes>` fixes this by allowing attributes to
be declared in a parent element which wraps the `<书社:link>`.

README.markdown
transforms/attributes.xslt [new file with mode: 0644]

index 13cb1d66fbc34cdaed3e28bd2e20a77b92a41cf9..cafda3aa533ebb233f4538f78ddba6e4b21f22a2 100644 (file)
@@ -283,6 +283,14 @@ Transforms are used to convert X·M·L files into their final output,
   after all necessary parsing and embedding has taken place.
 ⛩️📰 书社 comes with some transforms; namely :⁠—
 
+- **`transforms/attributes.xslt`:**
+  Applies transforms to the children of any `<书社:apply-attributes>`
+    elements, and then applies the attributes of the
+    `<书社:apply-attributes>` to each result child, replacing the
+    element with the result.
+  This is useful in combination with image embeds to apply alt‐text to
+    the resulting `<html:img>`.
+
 - **`transforms/asset.xslt`:**
   Converts `<html:object>` elements which correspond to recognized
     media types into the appropriate H·T·M·L elements, and deletes
diff --git a/transforms/attributes.xslt b/transforms/attributes.xslt
new file mode 100644 (file)
index 0000000..e91e7cb
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<!--
+⁌ ⛩️📰 书社 ∷ transforms/attributes.xslt
+
+© 2024 Lady [@ Lady’s 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/>.
+-->
+<transform
+       xmlns="http://www.w3.org/1999/XSL/Transform"
+       xmlns:exsl="http://exslt.org/common"
+       xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
+       exclude-result-prefixes="exsl"
+       version="1.0"
+>
+       <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:attributes.xslt</书社:id>
+       <template match="书社:apply-attributes">
+               <for-each select="node()">
+                       <choose>
+                               <when test="self::*">
+                                       <variable name="original" select="."/>
+                                       <variable name="result">
+                                               <apply-templates select="."/>
+                                       </variable>
+                                       <for-each select="exsl:node-set($result)/*">
+                                               <copy>
+                                                       <for-each select="@*|$original/../@*">
+                                                               <copy/>
+                                                       </for-each>
+                                                       <apply-templates/>
+                                               </copy>
+                                       </for-each>
+                               </when>
+                               <otherwise>
+                                       <apply-templates select="."/>
+                               </otherwise>
+                       </choose>
+               </for-each>
+       </template>
+</transform>
This page took 0.030706 seconds and 4 git commands to generate.