From: Lady <redacted>
Date: Sat, 20 Jan 2024 17:02:33 +0000 (-0500)
Subject: Pass single result tree to modes in wrapper
X-Git-Tag: 0.4.2^0
X-Git-Url: https://git.ladys.computer/Shushe/commitdiff_plain/bf451bf2f46fd1ea21f925ee02db620859cf2100?ds=inline

Pass single result tree to modes in wrapper

When matching a `<xslt:include>` inside of a `书社:metadata` transform,
it’s useful to be able to easily match elements in the result. Right
now, that requires a reference to the little‐documented variable
`$书社:result`, because `<xslt:include>` elements don’t belong to the
same document as result tree elements.

This commit creates a new tree which simply copies over all the result
nodes and all of the `<xslt:include>` elements, and then passes that to
the modal templates. Consequently, matches like `/html:div` or
`/xslt:include` should work regardless of what the current context node
is.
---

diff --git a/lib/catalog2transform.xslt b/lib/catalog2transform.xslt
index 1d36bb1..92dcaf9 100644
--- a/lib/catalog2transform.xslt
+++ b/lib/catalog2transform.xslt
@@ -121,10 +121,13 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 			<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="." mode="书社:metadata"/>
-					<xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:metadata"/>
+					<xslt:apply-templates select="exsl:node-set($modalinput)" mode="书社:metadata"/>
 				</xslt:variable>
 				<html:html>
 					<xslt:if test="$VERSION">
@@ -166,11 +169,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 					</html:head>
 					<html:body>
 						<xslt:copy-of select="html:html/html:body/@*|html:body/@*"/>
-						<xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:header"/>
-						<xslt:apply-templates select="." mode="书社:header"/>
+						<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="." mode="书社:footer"/>
-						<xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:footer"/>
+						<xslt:apply-templates select="exsl:node-set($modalinput)" mode="书社:footer"/>
 					</html:body>
 				</html:html>
 			</xslt:template>