Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2017-12-08 14:44:26 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2017-12-08 14:48:59 -0500
commitf38e6c896b88193cc38fae0fe5be07a2e9e864ea (patch)
tree8e247884a65ab610eaa4c5167cc7dedefebdaede
parent75aa0fab7e2fba6484fb32e3293892c43eb2327f (diff)
downloadtame-f38e6c896b88193cc38fae0fe5be07a2e9e864ea.tar.gz
tame-f38e6c896b88193cc38fae0fe5be07a2e9e864ea.tar.bz2
tame-f38e6c896b88193cc38fae0fe5be07a2e9e864ea.zip
Add template barriers for metadata
This (hopefully) prevents metadata from leaking outside of template expansions where they are not wanted. * src/current/include/preproc/macros.xsl (preproc:macropass): Strip cruft (new barrier nodes) on final pass. * src/current/include/preproc/template.xsl (preproc:expand-template): Enclose template expansion in preproc:tpl-barrier (which is stripped on the final pass). (preproc:apply-template)[lv:param-meta]: Document template. "Hoist" node (set attribute) if not contained within lv:param-copy. (preproc:gen-param-value)[lv:param-inherit]: Consider hoisted nodes behind barrier.
-rw-r--r--src/current/include/preproc/macros.xsl7
-rw-r--r--src/current/include/preproc/template.xsl71
2 files changed, 59 insertions, 19 deletions
diff --git a/src/current/include/preproc/macros.xsl b/src/current/include/preproc/macros.xsl
index 234632f..38721fd 100644
--- a/src/current/include/preproc/macros.xsl
+++ b/src/current/include/preproc/macros.xsl
@@ -2,7 +2,7 @@
<!--
Handles macro preprocessing
- Copyright (C) 2016 LoVullo Associates, Inc.
+ Copyright (C) 2016, 2017 LoVullo Associates, Inc.
This file is part of TAME.
@@ -79,9 +79,10 @@
</xsl:apply-templates>
</xsl:when>
- <!-- no more passes needed; macro expansion complete -->
+ <!-- no more passes needed; strip any cruft and we're done -->
<xsl:otherwise>
- <xsl:sequence select="$nodeset" />
+ <xsl:apply-templates mode="preproc:strip-tpl-cruft"
+ select="$nodeset" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
diff --git a/src/current/include/preproc/template.xsl b/src/current/include/preproc/template.xsl
index 7e80f59..6d7644e 100644
--- a/src/current/include/preproc/template.xsl
+++ b/src/current/include/preproc/template.xsl
@@ -305,21 +305,23 @@
template; this inlines it as if it were copied and pasted directly
into the XML, much like a C macro -->
<xsl:variable name="apply-result">
- <xsl:apply-templates
- select="$tpl[ 1 ]/*"
- mode="preproc:apply-template">
-
- <xsl:with-param name="apply" select="$context"
- tunnel="yes" />
- <xsl:with-param name="apply-tpl-name" select="$name"
- tunnel="yes" />
- <xsl:with-param name="params" select="$params"
- tunnel="yes" />
-
- <xsl:with-param name="first-child" select="true()" />
- <xsl:with-param name="src-root" select="$src-root"
- tunnel="yes" />
- </xsl:apply-templates>
+ <preproc:tpl-barrier>
+ <xsl:apply-templates
+ select="$tpl[ 1 ]/*"
+ mode="preproc:apply-template">
+
+ <xsl:with-param name="apply" select="$context"
+ tunnel="yes" />
+ <xsl:with-param name="apply-tpl-name" select="$name"
+ tunnel="yes" />
+ <xsl:with-param name="params" select="$params"
+ tunnel="yes" />
+
+ <xsl:with-param name="first-child" select="true()" />
+ <xsl:with-param name="src-root" select="$src-root"
+ tunnel="yes" />
+ </xsl:apply-templates>
+ </preproc:tpl-barrier>
</xsl:variable>
<xsl:apply-templates mode="preproc:mark-tpl-expansion"
@@ -337,6 +339,30 @@
<!--
+ Strip tpl barriers, which serve to scope metadata.
+-->
+<xsl:template mode="preproc:strip-tpl-cruft" priority="5"
+ match="preproc:tpl-barrier">
+ <xsl:apply-templates mode="preproc:strip-tpl-cruft"
+ select="node()" />
+</xsl:template>
+
+<!--
+ Everything else stays.
+-->
+<xsl:template mode="preproc:strip-tpl-cruft" priority="3"
+ match="node()">
+ <xsl:copy>
+ <xsl:sequence select="@*" />
+
+ <xsl:apply-templates mode="preproc:strip-tpl-cruft"
+ select="node()" />
+ </xsl:copy>
+</xsl:template>
+
+
+
+<!--
Add nodes describing where the parent node came from.
This helps in debugging and understanding code created by templates.
@@ -568,6 +594,13 @@
</xsl:template>
+<!--
+ Generate template metadata from lv:param-meta nodes.
+
+ Metadata contained within an lv:param-copy has its scope limited to
+ children only. Standalone lv:param-meta nodes are "hoisted" and are
+ available to siblings.
+-->
<xsl:template match="lv:param-meta" mode="preproc:apply-template" priority="5">
<xsl:param name="apply" as="node()"
tunnel="yes" />
@@ -579,7 +612,11 @@
</xsl:call-template>
</xsl:variable>
- <preproc:tpl-meta name="{@name}" value="{$value}" />
+ <preproc:tpl-meta name="{@name}" value="{$value}">
+ <xsl:if test="not( parent::lv:param-copy )">
+ <xsl:attribute name="hoist" select="'true'" />
+ </xsl:if>
+ </preproc:tpl-meta>
</xsl:template>
@@ -985,6 +1022,8 @@
<!-- find the metadata -->
<xsl:variable name="values"
select="$apply/ancestor::*/preceding-sibling::preproc:tpl-meta[ @name=$name ]/@value
+ , $apply/ancestor::*/preproc:tpl-barrier
+ /preproc:tpl-meta[ @hoist = 'true' and @name=$name ]/@value
, $apply/preceding-sibling::preproc:tpl-meta[ @name=$name ]/@value" />
<!-- take the last one (precedence) -->