Skip to content

Commit ac7a3f7

Browse files
committed
Fix substitute variables in macro calls
With the introduction of nested macros in entities (see commit 6d9d79b) it becomes necessary to substitute variables in the attributes of the `call-macro` element.
1 parent 56a7698 commit ac7a3f7

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/main/java/org/culturegraph/mf/morph/AbstractMetamorphDomWalker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private void handleRule(final Node node) {
312312
throw new MorphDefException("Macro '" + macroName + "' undefined!");
313313
}
314314
vars = new ScopedHashMap<String, String>(vars);
315-
vars.putAll(attributeMap(node));
315+
vars.putAll(resolvedAttributeMap(node));
316316
handleRules(macroNode);
317317
vars = vars.getOuterScope();
318318
}else {

src/test/java/org/culturegraph/mf/morph/MacroTest.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,53 @@
187187
</result>
188188
</test-case>
189189

190+
<test-case name="nested macros with variables being passed through">
191+
<input type="text/x-cg+xml">
192+
<cgxml:cgxml version="1.0">
193+
<cgxml:records>
194+
<cgxml:record id="1">
195+
<cgxml:literal name="country" value="Hawaii" />
196+
</cgxml:record>
197+
</cgxml:records>
198+
</cgxml:cgxml>
199+
</input>
200+
201+
<transformation type="text/x-metamorph+xml">
202+
<mm:metamorph version="1" entityMarker=".">
203+
<mm:macros>
204+
<mm:macro name="prepend">
205+
<mm:data source="country">
206+
<mm:compose prefix="$[with]" />
207+
</mm:data>
208+
</mm:macro>
209+
210+
<mm:macro name="wrapInEntity">
211+
<mm:entity name="entity">
212+
<mm:call-macro name="prepend" with="$[prefix]" />
213+
</mm:entity>
214+
</mm:macro>
215+
</mm:macros>
216+
<mm:rules>
217+
<mm:call-macro name="wrapInEntity" prefix="1: " />
218+
<mm:call-macro name="wrapInEntity" prefix="2: " />
219+
</mm:rules>
220+
</mm:metamorph>
221+
</transformation>
222+
223+
<result type="text/x-cg+xml">
224+
<cgxml:cgxml version="1.0">
225+
<cgxml:records>
226+
<cgxml:record id="1">
227+
<cgxml:entity name="entity">
228+
<cgxml:literal name="country" value="1: Hawaii"/>
229+
</cgxml:entity>
230+
<cgxml:entity name="entity">
231+
<cgxml:literal name="country" value="2: Hawaii"/>
232+
</cgxml:entity>
233+
</cgxml:record>
234+
</cgxml:records>
235+
</cgxml:cgxml>
236+
</result>
237+
</test-case>
238+
190239
</metamorph-test>

0 commit comments

Comments
 (0)