$(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,<object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) > $(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,<object xmlns="http://www.w3.org/1999/xhtml" type="$(call typeoffile,$<)" data="$(call datauri,$<)"/>) > $(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.
 #
 $(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 $@))
 
   is an asset, in which case an `<html:object>` 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.
   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
   - **`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.
 
 - **`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).
 
 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
+  `<html:div>`.
+
+## 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
 
 
 -->
 <!DOCTYPE transform [
        <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
+       <!ENTITY xml "http://www.w3.org/XML/1998/namespace">
 ]>
 <transform
        xmlns="http://www.w3.org/1999/XSL/Transform"
                        <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
                        <xslt:param name="CKSUM" select="false"/>
                        <xslt:param name="CATALOG" select="'catalog'"/>
+                       <xslt:param name="IDENTIFIER" select="false"/>
                        <xslt:param name="PATH" select="'/unknown'"/>
                        <xslt:param name="SRCREV" select="false"/>
                        <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
                        <xslt:param name="THISREV" select="false"/>
+                       <xslt:variable name="书社:source" select="/"/>
                        <xslt:variable name="书社:expansion">
-                               <xslt:apply-templates select="/" mode="书社:expand"/>
+                               <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
                        </xslt:variable>
                        <xslt:variable name="书社:result">
-                               <xslt:apply-templates select="exsl:node-set($书社:expansion)/*"/>
+                               <xslt:apply-templates select="exsl:node-set($书社:expansion)/node()"/>
                        </xslt:variable>
                        <for-each select="//catalog:uri">
                                <xslt:include href="{@uri}">
                                        </if>
                                </xslt:include>
                        </for-each>
-                       <xslt:template match="/" priority="1">
-                               <xslt:choose>
-                                       <xslt:when test="exsl:node-set($书社:result)/*[@书社:disable-output-wrapping]">
-                                               <xslt:for-each select="exsl:node-set($书社:result)/*">
+                       <xslt:template name="书社:apply-attributes">
+                               <xslt:param name="and-version" select="false"/>
+                               <xslt:param name="context-nodes" select="/.."/>
+                               <xslt:param name="destination-nodes" select="/.."/>
+                               <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
+                               <xslt:for-each select="$destination-nodes">
+                                       <xslt:variable name="existing-attributes" select="@*"/>
+                                       <xslt:choose>
+                                               <xslt:when test="self::*">
+                                                       <xslt:variable name="context" select="."/>
+                                                       <xslt:variable name="attribute-names">
+                                                               <xslt:for-each select="$existing-attributes|$additional-attributes">
+                                                                       <书社:attribute>
+                                                                               <attribute name="local-name">
+                                                                                       <text>{local-name()}</text>
+                                                                               </attribute>
+                                                                               <attribute name="name">
+                                                                                       <text>{name()}</text>
+                                                                               </attribute>
+                                                                               <attribute name="namespace-uri">
+                                                                                       <text>{namespace-uri()}</text>
+                                                                               </attribute>
+                                                                       </书社:attribute>
+                                                               </xslt:for-each>
+                                                       </xslt:variable>
+                                                       <xslt:variable name="lang">
+                                                               <xslt:choose>
+                                                                       <xslt:when test="(self::html:*|self::svg:*)/@lang">
+                                                                               <xslt:value-of select="@lang"/>
+                                                                       </xslt:when>
+                                                                       <xslt:when test="@xml:lang">
+                                                                               <xslt:value-of select="@xml:lang"/>
+                                                                       </xslt:when>
+                                                                       <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
+                                                                               <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
+                                                                       </xslt:when>
+                                                                       <xslt:when test="(self::html:* or self::svg:*) and $additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']">
+                                                                               <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
+                                                                       </xslt:when>
+                                                                       <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
+                                                                               <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
+                                                                       </xslt:when>
+                                                               </xslt:choose>
+                                                       </xslt:variable>
                                                        <xslt:copy>
-                                                               <xslt:if test="$THISREV">
+                                                               <xslt:if test="$and-version and $THISREV">
                                                                        <xslt:attribute name="书社:version">
                                                                                <xslt:value-of select="$THISREV"/>
                                                                        </xslt:attribute>
                                                                </xslt:if>
-                                                               <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and contains('disable-output-wrapping version', local-name()))]|node()"/>
+                                                               <xslt:if test="string($lang)!=''">
+                                                                       <xslt:if test="self::html:* or self::svg:*">
+                                                                               <xslt:attribute name="lang">
+                                                                                       <xslt:value-of select="$lang"/>
+                                                                               </xslt:attribute>
+                                                                       </xslt:if>
+                                                                       <xslt:attribute name="xml:lang">
+                                                                               <xslt:value-of select="$lang"/>
+                                                                       </xslt:attribute>
+                                                               </xslt:if>
+                                                               <xslt:for-each select="exsl:node-set($attribute-names)/*">
+                                                                       <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='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>
+                                                                                       <xslt:attribute>
+                                                                                               <attribute name="name">
+                                                                                                       <text>{@name}</text>
+                                                                                               </attribute>
+                                                                                               <attribute name="namespace">
+                                                                                                       <text>{@namespace-uri}</text>
+                                                                                               </attribute>
+                                                                                               <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
+                                                                                                       <xslt:value-of select="."/>
+                                                                                                       <xslt:if test="position()!=last()">
+                                                                                                               <xslt:text>
+                                                                                                                       <text> </text>
+                                                                                                               </xslt:text>
+                                                                                                       </xslt:if>
+                                                                                               </xslt:for-each>
+                                                                                               <xslt:if test="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri] and $additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
+                                                                                                       <xslt:text>
+                                                                                                               <text> </text>
+                                                                                                       </xslt:text>
+                                                                                               </xslt:if>
+                                                                                               <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
+                                                                                                       <xslt:value-of select="."/>
+                                                                                                       <xslt:if test="position()!=last()">
+                                                                                                               <xslt:text>
+                                                                                                                       <text> </text>
+                                                                                                               </xslt:text>
+                                                                                                       </xslt:if>
+                                                                                               </xslt:for-each>
+                                                                                       </xslt:attribute>
+                                                                               </xslt:otherwise>
+                                                                       </xslt:choose>
+                                                               </xslt:for-each>
+                                                               <xslt:copy-of select="node()"/>
                                                        </xslt:copy>
-                                               </xslt:for-each>
-                                       </xslt:when>
-                                       <xslt:otherwise>
-                                               <xslt:apply-templates select="exsl:node-set($书社:result)" mode="书社:wrap"/>
-                                       </xslt:otherwise>
-                               </xslt:choose>
+                                               </xslt:when>
+                                               <xslt:otherwise>
+                                                       <xslt:copy-of select="."/>
+                                               </xslt:otherwise>
+                                       </xslt:choose>
+                               </xslt:for-each>
+                       </xslt:template>
+                       <xslt:template name="书社:wrap">
+                               <xslt:param name="nodes" select="/.."/>
+                               <xslt:variable name="modalinput">
+                                       <xslt:copy-of select="$nodes"/>
+                                       <xslt:copy-of select="document('')/xslt:transform/xslt:include"/>
+                               </xslt:variable>
+                               <xslt:variable name="metadata">
+                                       <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
+                                       <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:metadata"/>
+                               </xslt:variable>
+                               <html:html>
+                                       <xslt:copy-of select="$nodes[self::html:html]/@*"/>
+                                       <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
+                                               <xslt:attribute name="lang">
+                                                       <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
+                                               </xslt:attribute>
+                                       </xslt:if>
+                                       <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
+                                               <xslt:attribute name="xml:lang">
+                                                       <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
+                                               </xslt:attribute>
+                                       </xslt:if>
+                                       <html:head>
+                                               <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
+                                               <html:title>
+                                                       <xslt:for-each select="exsl:node-set($metadata)/html:title">
+                                                               <xslt:value-of select="."/>
+                                                               <xslt:if test="position()!=last()">
+                                                                       <xslt:text>
+                                                                               <text> </text>
+                                                                       </xslt:text>
+                                                               </xslt:if>
+                                                       </xslt:for-each>
+                                               </html:title>
+                                               <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::html:title)]"/>
+                                               <html:meta name="generator">
+                                                       <xslt:attribute name="content">
+                                                               <xslt:for-each select="exsl:node-set($metadata)/html:meta[@name='generator']">
+                                                                       <xslt:value-of select="@content"/>
+                                                                       <xslt:text>
+                                                                               <text>, </text>
+                                                                       </xslt:text>
+                                                               </xslt:for-each>
+                                                               <xslt:text>
+                                                                       <text>⛩️📰 书社</text>
+                                                               </xslt:text>
+                                                               <xslt:if test="$THISREV">
+                                                                       <xslt:text>
+                                                                               <text> (</text>
+                                                                       </xslt:text>
+                                                                       <xslt:value-of select="$THISREV"/>
+                                                                       <xslt:text>
+                                                                               <text>)</text>
+                                                                       </xslt:text>
+                                                               </xslt:if>
+                                                       </xslt:attribute>
+                                               </html:meta>
+                                       </html:head>
+                                       <html:body>
+                                               <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
+                                               <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:header"/>
+                                               <xslt:copy-of select="$nodes[not(self::html:html or self::html:head or self::html:body)]|$nodes[self::html:html]/node()[not(self::html:head or self::html:body)]|$nodes[self::html:html]/html:body/node()|$nodes[self::html:body]/node()"/>
+                                               <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:footer"/>
+                                       </html:body>
+                               </html:html>
+                       </xslt:template>
+                       <xslt:template match="/" priority="1">
+                               <xslt:variable name="result-nodes" select="exsl:node-set($书社:result)/node()[not(self::书社:apply-attributes-to-root)]|exsl:node-set($书社: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="root-with-attributes">
+                                       <xslt:choose>
+                                               <xslt:when test="$result-nodes/@书社:disable-output-wrapping|exsl:node-set($书社: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="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
+                                                               <xslt:with-param name="destination-nodes" select="$result-nodes"/>
+                                                       </xslt:call-template>
+                                               </xslt:when>
+                                               <xslt:otherwise>
+                                                       <xslt:variable name="wrapped-result">
+                                                               <xslt:call-template name="书社:wrap">
+                                                                       <xslt:with-param name="nodes" select="$result-nodes"/>
+                                                               </xslt:call-template>
+                                                       </xslt:variable>
+                                                       <xslt:call-template name="书社:apply-attributes">
+                                                               <xslt:with-param name="and-version" select="true"/>
+                                                               <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
+                                                               <xslt:with-param name="destination-nodes" select="exsl:node-set($wrapped-result)/node()"/>
+                                                       </xslt:call-template>
+                                               </xslt:otherwise>
+                                       </xslt:choose>
+                               </xslt:variable>
+                               <xslt:apply-templates select="exsl:node-set($root-with-attributes)/node()" mode="书社:application"/>
                        </xslt:template>
-                       <xslt:template match="/*/*//@书社:disable-output-wrapping|//@书社:destination" priority="0"/>
                        <xslt:template match="@*|node()" priority="-1">
                                <xslt:copy>
                                        <xslt:apply-templates select="@*|node()"/>
                                </xslt:copy>
                        </xslt:template>
-                       <xslt:template match="/*" mode="书社:expand" priority="0">
+                       <xslt:template match="@*|node()" mode="书社:application">
                                <xslt:copy>
-                                       <xslt:attribute name="itemscope">itemscope</xslt:attribute>
-                                       <xslt:attribute name="itemtype">
-                                               <xslt:text>&书社;:document</xslt:text>
-                                               <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
-                                                       <xslt:text> </xslt:text>
-                                                       <xslt:value-of select="."/>
-                                               </xslt:for-each>
+                                       <xslt:apply-templates select="@*|node()" mode="书社:application"/>
+                               </xslt:copy>
+                       </xslt:template>
+                       <xslt:template match="@书社:destination|@书社:disable-output-wrapping" mode="书社:application" priority="1"/>
+                       <xslt:template match="书社:apply-attributes" mode="书社:application" priority="1">
+                               <xslt:variable name="children">
+                                       <xslt:apply-templates select="node()" mode="书社:application"/>
+                               </xslt:variable>
+                               <xslt:call-template name="书社:apply-attributes">
+                                       <xslt:with-param name="context-nodes" select="."/>
+                                       <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
+                               </xslt:call-template>
+                       </xslt:template>
+                       <xslt:template match="书社:apply-attributes-to-root" mode="书社:application" priority="1">
+                               <xslt:apply-templates select="node()" mode="书社:application"/>
+                       </xslt:template>
+                       <xslt:template match="/node()" mode="书社:expand" priority="0">
+                               <xslt:copy>
+                                       <xslt:attribute name="书社:identifier">
+                                               <xslt:value-of select="$IDENTIFIER"/>
                                        </xslt:attribute>
-                                       <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
+                                       <xslt:choose>
+                                               <xslt:when test="self::html:*">
+                                                       <xslt:attribute name="itemscope">itemscope</xslt:attribute>
+                                                       <xslt:attribute name="itemtype">
+                                                               <xslt:text>
+                                                                       <text>&书社;:document</text>
+                                                               </xslt:text>
+                                                               <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
+                                                                       <xslt:text>
+                                                                               <text> </text>
+                                                                       </xslt:text>
+                                                                       <xslt:value-of select="."/>
+                                                               </xslt:for-each>
+                                                       </xslt:attribute>
+                                                       <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
+                                               </xslt:when>
+                                               <xslt:otherwise>
+                                                       <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
+                                               </xslt:otherwise>
+                                       </xslt:choose>
                                </xslt:copy>
                        </xslt:template>
                        <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
-                               <xslt:variable name="uri" select="substring-before(document($CATALOG)//catalog:uri[@name=current()/@xlink:href]/@uri[1], '#')"/>
+                               <xslt:variable name="identifier" select="string(@xlink:href)"/>
+                               <xslt:variable name="uri" select="substring-before(document($CATALOG)//catalog:uri[@name=$identifier]/@uri[1], '#')"/>
                                <xslt:choose>
                                        <xslt:when test="$uri">
                                                <xslt:variable name="expanded">
                                                        <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
                                                </xslt:variable>
-                                               <xslt:for-each select="exsl:node-set($expanded)/*">
+                                               <xslt:for-each select="exsl:node-set($expanded)/node()">
                                                        <xslt:copy>
-                                                               <xslt:attribute name="itemscope">itemscope</xslt:attribute>
-                                                               <xslt:attribute name="itemtype">
-                                                                       <xslt:text>&书社;:embed</xslt:text>
-                                                                       <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
-                                                                               <xslt:text> </xslt:text>
-                                                                               <xslt:value-of select="."/>
-                                                                       </xslt:for-each>
+                                                               <xslt:attribute name="书社:identifier">
+                                                                       <xslt:value-of select="$identifier"/>
                                                                </xslt:attribute>
-                                                               <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
+                                                               <xslt:choose>
+                                                                       <xslt:when test="self::html:*">
+                                                                               <xslt:attribute name="itemscope">itemscope</xslt:attribute>
+                                                                               <xslt:attribute name="itemtype">
+                                                                                       <xslt:text>
+                                                                                               <text>&书社;:embed</text>
+                                                                                       </xslt:text>
+                                                                                       <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
+                                                                                               <xslt:text>
+                                                                                                       <text> </text>
+                                                                                               </xslt:text>
+                                                                                               <xslt:value-of select="."/>
+                                                                                       </xslt:for-each>
+                                                                               </xslt:attribute>
+                                                                               <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='identifier')]|node()"/>
+                                                                       </xslt:when>
+                                                                       <xslt:otherwise>
+                                                                               <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and local-name()='identifier')]|node()" mode="书社:expand"/>
+                                                                       </xslt:otherwise>
+                                                               </xslt:choose>
                                                        </xslt:copy>
                                                </xslt:for-each>
                                        </xslt:when>
                                        </xslt:otherwise>
                                </xslt:choose>
                        </xslt:template>
-                       <xslt:template match="@*|text()|*[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
+                       <xslt:template match="@*|node()[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
                                <xslt:copy>
                                        <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
                                </xslt:copy>
                        <xslt:template match="text()" mode="书社:header"/>
                        <xslt:template match="text()" mode="书社:footer"/>
                        <xslt:template match="text()" mode="书社:metadata"/>
-                       <xslt:template match="/" mode="书社:wrap">
-                               <xslt:variable name="modalinput">
-                                       <xslt:copy-of select="node()"/>
-                                       <xslt:copy-of select="document('')/xslt:transform/xslt:include"/>
-                               </xslt:variable>
-                               <xslt:variable name="metadata">
-                                       <xslt:copy-of select="html:html/html:head/node()|html:head/node()"/>
-                                       <xslt:apply-templates select="exsl:node-set($modalinput)" mode="书社:metadata"/>
-                               </xslt:variable>
-                               <html:html>
-                                       <xslt:if test="$THISREV">
-                                               <xslt:attribute name="书社:version">
-                                                       <xslt:value-of select="$THISREV"/>
-                                               </xslt:attribute>
-                                       </xslt:if>
-                                       <xslt:copy-of select="html:html/@*"/>
-                                       <xslt:if test="not(html:html/@lang) and (html:*/@lang|svg:*/@lang|*/@xml:lang)">
-                                               <xslt:attribute name="lang">
-                                                       <xslt:value-of select="html:*/@lang|svg:*/@lang|*/@xml:lang"/>
-                                               </xslt:attribute>
-                                       </xslt:if>
-                                       <xslt:if test="not(html:html/@xml:lang) and (html:*/@lang|svg:*/@lang|*/@xml:lang)">
-                                               <xslt:attribute name="xml:lang">
-                                                       <xslt:value-of select="html:*/@lang|svg:*/@lang|*/@xml:lang"/>
-                                               </xslt:attribute>
-                                       </xslt:if>
-                                       <html:head>
-                                               <xslt:copy-of select="html:html/html:head/@*|html:head/@*"/>
-                                               <html:title>
-                                                       <xslt:for-each select="exsl:node-set($metadata)/html:title">
-                                                               <xslt:value-of select="."/>
-                                                       </xslt:for-each>
-                                               </html:title>
-                                               <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::*) or not(self::html:title)]"/>
-                                               <html:meta name="generator">
-                                                       <xslt:attribute name="content">
-                                                               <xslt:for-each select="exsl:node-set($metadata)/html:meta[@name='generator']">
-                                                                       <xslt:value-of select="@content"/>
-                                                                       <xslt:text>, </xslt:text>
-                                                               </xslt:for-each>
-                                                               <xslt:text>⛩️📰 书社</xslt:text>
-                                                               <xslt:if test="$THISREV">
-                                                                       <xslt:text> (</xslt:text>
-                                                                       <xslt:value-of select="$THISREV"/>
-                                                                       <xslt:text>)</xslt:text>
-                                                               </xslt:if>
-                                                       </xslt:attribute>
-                                               </html:meta>
-                                       </html:head>
-                                       <html:body>
-                                               <xslt:copy-of select="html:html/html:body/@*|html:body/@*"/>
-                                               <xslt:apply-templates select="exsl:node-set($modalinput)" mode="书社:header"/>
-                                               <xslt:copy-of select="node()[not(self::html:html or self::html:head or self::html:body)]|html:html/node()[not(self::html:head or self::html:body)]|html:html/html:body/node()|html:body/node()"/>
-                                               <xslt:apply-templates select="exsl:node-set($modalinput)" mode="书社:footer"/>
-                                       </html:body>
-                               </html:html>
-                       </xslt:template>
                        <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>
                </xslt:transform>
        </template>