From: Lady Date: Thu, 8 Feb 2024 03:41:33 +0000 (-0500) Subject: Refactor transforms & add 书社:application stage X-Git-Tag: 0.6.0^0 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/c00fbad125caaac8be191801ca47a6971007fbad?hp=d64d93fe12371f87cc42d72e7e874115b28fb252 Refactor transforms & add 书社:application stage The main goal of this commit was to add a `<书社:apply-attributes-to-root>` element, to allow transforms to pass attributes up to the root element of the result, for example `@lang` information. This required an extensive refactor of a lot of the transform infrastructure and the creation of a new transform stage, `书社:application`, which follows the ordinary transform and solely handles `<书社:apply-attributes-to-root>` and `<书社:apply-attributes>`. Other `@书社:*` attributes are removed at this stage, but it isn’t generally recommended that transforms try to hook in here. This commit also makes a number of smaller changes :⁠— - Use `node()` in place of element wildcards anywhere where specifically only matching elements wasn’t intended. In particular, even in places where text is not expected, there may be comments to preserve. - Only add `@itemscope` and `@itemtype` attributes to H·T·M·L elements, since they are only defined for elements in that namespace. - Provide `@书社:identifier` on documents and embeds to get the `about:shushe` u·r·i of the resource. - In transforms which generate transforms, `` elements which provide only white·space need `` children to ensure the whitespace isn’t stripped. (Note: In the actual source text, `xsla:` is given the `xslt:` prefix and `xslt:` is the default prefix.) Similarly, it’s necessary to provide attribute value templates using a `` element rather than with the literal result element syntax, to prevent them from being prematurely applied. --- diff --git a/GNUmakefile b/GNUmakefile index f0c9e8a..1697903 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -497,7 +497,7 @@ $(BUILDDIR)/parser.xslt : $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2pars $(call parsed,$(sourcefiles) $(sourceincludes)) : % : $$(call unparsed,$$@) $(BUILDDIR)/parser.xslt $(typeupdates) @$(PRINTF) '%s\n' $(call quote,Processing `$<´…) $(silent)$(call ensuredirectory,$(dir $@)) - $(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,) > $(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(CAT) $(call quote,$<)) | $(XSLTPROC) -o $(call quote,$@) --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$<)) --stringparam CKSUM $$($(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) -) + $(silent)$(if $(filter $<,$(assetfiles)),$(PRINTF) '%s\n' $(call quote,) > $(call quote,$@),$(if $(filter $<,$(plaintextfiles)),$(call wrapplaintext,$<),$(CAT) $(call quote,$<)) | $(XSLTPROC) -o $(call quote,$@) --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam IDENTIFIER $(call quote,$(call localuri,$<)) --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$<)) --stringparam CKSUM $$($(CKSUM) $(call quote,$<) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/parser.xslt) -) # Generate a catalog of all parsed files, for use when processing includes. # @@ -533,7 +533,7 @@ $(BUILDDIR)/transform.xslt : $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalo $(call compiled,$(compilablefiles)) : $(BUILDDIR)/public/% : $$(call parsed,$$(call uncompiled,$$@)) $(BUILDDIR)/transform.xslt $$(call parsed,$$(call dependencies,$$(call uncompiled,$$@))) $(silent)$(call ensuredirectory,$(dir $@)) @$(PRINTF) '%s\n' $(call quote,Compiling …) - $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<) + $(silent)$(XSLTPROC) -o $(call quote,$@) --stringparam CATALOG 'catalog' --stringparam BUILDTIME $$(TZ= $(DATE) '+%Y-%m-%dT%H:%M:%SZ') --stringparam SRCTIME $$(TZ= $(STAT) -f '%Sm' -t '%Y-%m-%dT%H:%M:%SZ' $(call quote,$(call uncompiled,$@))) --stringparam IDENTIFIER $(call quote,$(call localuri,$(call uncompiled,$@))) --stringparam PATH $(call quote,/$*) --stringparam CKSUM $$($(CKSUM) $(call quote,$(call uncompiled,$@)) | $(SED) 's/[ ].*//')$(if $(THISREV), --stringparam THISREV $(call quote,$(THISREV)),)$(if $(SRCREV), --stringparam SRCREV $(call quote,$(SRCREV)),) $(call quote,$(BUILDDIR)/transform.xslt) $(call quote,$<) $(call compiled,$(filter $(assetfiles),$(sourcefiles))) : $(BUILDDIR)/public/% : $$(call uncompiled,$$@) @$(PRINTF) '%s\n' $(call quote,Compiling …) $(silent)$(call ensuredirectory,$(dir $@)) diff --git a/README.markdown b/README.markdown index 6b4f06e..f6a0864 100644 --- a/README.markdown +++ b/README.markdown @@ -379,6 +379,8 @@ Embeds are replaced with the parsed contents of a file, unless the file is an asset, in which case an `` element is produced instead (with the contents of the asset file provided as a base64 `data:` u·r·i). +Embed replacements will be given a `@书社:identifier` attribute whose + value will match the `@xlink:href` of the embed. Embedding takes place after parsing but before transformation, so parsers are able to generate their own embeds. @@ -401,14 +403,6 @@ 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 ``. - - **`transforms/asset.xslt`:** Converts `` elements which correspond to recognized media types into the appropriate H·T·M·L elements, and deletes @@ -423,8 +417,8 @@ Transforms are used to convert X·M·L files into their final output, - **`urn:fdc:ladys.computer:20231231:Shu1She4:title`:** Provides the title of the page. - ⛩️📰 书社 automatically encapsulates embeds so that their metadata - does not propogate up to the embedding document. + ⛩️📰 书社 automatically encapsulates H·T·M·L embeds so that their + metadata does not propogate up to the embedding document. To undo this behaviour, remove the `@itemscope` and `@itemtype` attributes from the embed during the transformation phase. @@ -451,6 +445,10 @@ The following params are made available globally in parsers and - **`CKSUM`:** The checksum of the source file (⅌ `cksum`). +- **`IDENTIFIER`:** + The ⛩️📰 书社 identifier of the source file (a u·r·i beginning with + `about:shushe`). + - **`SRCREV`:** The value of the `SRCREV` variable (if present). @@ -520,6 +518,29 @@ This mechanism can be used to allow transforms to insert content Output wrapping can be entirely disabled by adding a `@书社:disable-output-wrapping` attribute to the top‐level element in the result tree. +This attribute will also prevent wrapping non‐H·T·M·L embeds with an + ``. + +## Applying Attributes + +The `<书社:apply-attributes>` element will apply any attributes on the + element to the element(s) it wraps. +It is especially useful in combination with embeds. + +The `<书社:apply-attributes-to-root>` element will apply any attributes + on the element to the root node of the final transformation result. +It is especially useful in combination with output wrapping. + +In both cases, attributes from various sources are combined with + white·space between them. +Attribute application takes place after all ordinary transforms have + completed. + +Both elements ignore attributes in the `xml:` namespace, except for + `@xml:lang`, which ignores all but the first definition (including + any already present on the root element). +On H·T·M·L and S·V·G elements, `@lang` has the same behaviour as + `@xml:lang`. ## License diff --git a/lib/catalog2parser.xslt b/lib/catalog2parser.xslt index 4ea7bda..1faa880 100644 --- a/lib/catalog2parser.xslt +++ b/lib/catalog2parser.xslt @@ -24,6 +24,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one + @@ -94,7 +95,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one - + + + diff --git a/lib/catalog2transform.xslt b/lib/catalog2transform.xslt index a6c83d6..b53e12a 100644 --- a/lib/catalog2transform.xslt +++ b/lib/catalog2transform.xslt @@ -9,6 +9,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one --> + ]> + + - + - + @@ -47,62 +50,290 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one - - - - + + + + + + + + + + + + + <书社:attribute> + + {local-name()} + + + {name()} + + + {namespace-uri()} + + + + + + + + + + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + {@name} + + + {@namespace-uri} + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + , + + + + ⛩️📰 书社 + + + + ( + + + + ) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - itemscope - - &书社;:document - - - - + + + + + + + + + + + + + + + + + + + + - + + + itemscope + + + &书社;:document + + + + + + + + + + + + + + - + + - + - itemscope - - &书社;:embed - - - - + + - + + + itemscope + + + &书社;:embed + + + + + + + + + + + + + + @@ -113,7 +344,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one - + @@ -121,63 +352,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - , - - ⛩️📰 书社 - - ( - - ) - - - - - - - - - - - - diff --git a/transforms/asset.xslt b/transforms/asset.xslt index 0242f43..55b449b 100644 --- a/transforms/asset.xslt +++ b/transforms/asset.xslt @@ -19,20 +19,30 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:asset.xslt