+ </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-fragment">
+ <xslt:copy-of select="$nodes"/>
+ <apply-templates select="exsl:node-set($unique-ids)" mode="书社:literally"/>
+ </xslt:variable>
+ <xslt:variable name="modalinput" select="exsl:node-set($modalinput-fragment)"/>
+ <xslt:variable name="metadata-fragment">
+ <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
+ <xslt:apply-templates select="$modalinput/node()" mode="书社:metadata"/>
+ </xslt:variable>
+ <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
+ <html:html>
+ <xslt:copy-of select="$nodes[self::html:html]/@*"/>
+ <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
+ <xslt:attribute name="书社:archived-as">
+ <xslt:value-of select="$nodes/@书社:archived-as"/>
+ </xslt:attribute>
+ </xslt:if>
+ <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="$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="$metadata/node()[not(self::html:title or self::html:meta and @name='generator')]"/>
+ <html:meta name="generator">
+ <xslt:attribute name="content">
+ <xslt:for-each select="$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="$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="$modalinput/node()" mode="书社:footer"/>
+ </html:body>
+ </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//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($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"/>
+ <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="$书社: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="书社:apply"/>