From: Lady Date: Mon, 1 Jan 2024 16:19:37 +0000 (-0500) Subject: Allow creation of metadata without matching result X-Git-Tag: 0.2.0~8 X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/af8b42c720c6aaa54199b556a656d40e8b8951a6?ds=inline;hp=e7c797ffb120c0dac9be13b28d533d49d164b6d0 Allow creation of metadata without matching result Each node in the result can only be matched once in any given mode, and transforms need a mechanism for inserting elements without requiring a match. This commit gives them a means of doing so by also matching every `` in the main transform. If a transform has a `书社:id` top‐level element which is an i·r·i, then its include will have a corresponding attribute, and transforms can (by convention) match this include without fear of conflicts. This commit also makes the expansion and result available as top‐level variables in the `书社:` namespace, so that transforms can easily match within them. --- diff --git a/GNUmakefile b/GNUmakefile index e0cb8e1..72712c8 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -224,6 +224,9 @@ override assetfiles := $(filter-out $(xmlfiles) $(plaintextfiles),$(sourcefiles) # (callable) Get the types of the given files. override typeoffile = $(patsubst $(foreach file,$1,$(file)?type=%),%,$(filter $(foreach file,$1,$(file)?type=%),$(types))) +# (callable) Get the identifier for the given transform. +override id = $(or $(shell $(XMLLINT) --xpath '/*/*[local-name()="id" and namespace-uri()="urn:fdc:ladys.computer:20231231:Shu1She4"]/text()[1]' $1),$(basename $(notdir $1)) | $(SED)) + # (callable) Get base64 data u·r·i’s for the given files. override datauri = $(foreach file,$1,data:$(call typeoffile,$(file));base64,$(shell $(UUENCODE) -m -r $(call quote,$(file)) _ | tr -d ' \n')) @@ -378,7 +381,7 @@ $(BUILDDIR)/magic.mgc: $(wildcard $(MAGICDIR)/*) $(BUILDDIR)/parser.catalog: $(PARSERS) @$(ECHO) "Generating catalog of parsers…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) - $(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(basename $(notdir $(parser)))) $(call quote,../$(parser)) --noout $(call quote,$@)$(newline)) + $(foreach parser,$(PARSERS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(parser))) $(call quote,../$(parser)) --noout $(call quote,$@)$(newline)) $(BUILDDIR)/parser.xslt: $(BUILDDIR)/parser.catalog $(THISDIR)/lib/catalog2parser.xslt @$(ECHO) "Generating main parser…" $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2parser.xslt) $(call quote,$<) @@ -419,7 +422,7 @@ $(BUILDDIR)/dependencies: $(BUILDDIR)/catalog $(call parsed,$(plaintextfiles) $( $(BUILDDIR)/transform.catalog: $(TRANSFORMS) @$(ECHO) "Generating catalog of transforms…" $(silent)$(XMLCATALOG) --create --noout $(call quote,$@) - $(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(basename $(notdir $(transform)))) $(call quote,../$(transform)) --noout $(call quote,$@)$(newline)) + $(foreach transform,$(TRANSFORMS),$(silent)$(XMLCATALOG) --add uri $(call quote,$(call id,$(transform))) $(call quote,../$(transform)) --noout $(call quote,$@)$(newline)) $(BUILDDIR)/transform.xslt: $(BUILDDIR)/transform.catalog $(THISDIR)/lib/catalog2transform.xslt @$(ECHO) "Generating main transform…" $(silent)$(XSLTPROC) -o $(call quote,$@) $(call quote,$(THISDIR)/lib/catalog2transform.xslt) $(call quote,$<) diff --git a/README.markdown b/README.markdown index 2dd0eff..84c3206 100644 --- a/README.markdown +++ b/README.markdown @@ -313,10 +313,41 @@ The following are recommendations on effective creation of ⛩️📰 书社 will wrap the final output of the transforms in appropriate `` and `` elements, so it is not necessary for transforms to do this explicitly. -The `` of the output will contain the result tree generated - by matching the root node in the `书社:metadata` mode; the provided - `transforms/metadata.xslt` transform uses this mode to generate basic - metadata, but it is possible for other transforms to add their own. +After performing the initial transform, ⛩️📰 书社 will match the root + node of the result in the following modes to fill in areas of the + wrapper :⁠— + +- **`书社:metadata`:** + The result of matching in this mode is inserted into the + `` of the output. + +In addition to being called with the transform result, each of these + modes will additionally be called with a `` element + corresponding to each transform. +If a transform has a `<书社:id>` top‐level element whose value is an + i·r·i, its `` element will have a corresponding + `@书社:id` attribute. +This mechanism can be used to allow transforms to insert content + without matching any elements in the result; for example, the + following transform adds a link to a stylesheet to the `` + of every page :⁠— + +```xml + + + <书社:id>example:add-stylesheet-links.xslt + + +``` ## License diff --git a/lib/catalog2parser.xslt b/lib/catalog2parser.xslt index d044503..0da26b8 100644 --- a/lib/catalog2parser.xslt +++ b/lib/catalog2parser.xslt @@ -2,7 +2,7 @@