Express maps

Hi,

I have the following rule

to create a map and then add an

additional map entry:

<block>

<defvar name='myMap'/>

<!-- Create a map -->

<set name='myMap'>

<map>

<s>a</s>

<s>A</s>

<s>b</s>

<s>B</s>

</map>

</set>

<!-- Add a map entry -->

<set>

<ref>myMap</ref>

<s>c</s>

<s>C</s>

</set>

<!-- Print the entire map -->

<print>

<ref>myMap</ref>

</print>

<ref>myMap</ref>

</block>

The print statement prints:

{a=A, b=B}

whereas I think it should print:

{a=A, b=B, c=C}

The complete block of code

returns:

<Map>

<MapEntry key='a' value='A'/>

<MapEntry key='b' value='B'/>

<MapEntry key='c' value='C'/>

</Map>

So it does look like the additional

entry is being added to the map.

Does anyone know why the print

statement does not print the modified map?

Thanks,

John I

[1276 byte] By [johni] at [2007-11-26 8:59:02]
# 1

Does seem strange. I create a sample rule that contains your code and it is interesting to see the trace where the </block> does not return the entire list, but the </Rule> does (trace below the message).

Not sure how the processing goes on internally, but here's the fix (either 1 or 2 will work):

1) Remove the <defvar name='myMap'/>.... i.e. set the variable directly.

2) Every time you change the map, refresh it with a statement like this:

<set name='myMap'>

<ref>myMap</ref>

</set>

Hope this helps.

Adi.

Trace for the original rule:

<Rule name='New Rule'>

<block>

<defvar name='myMap'>

</defvar> --> null

<set name='myMap'>

<map>

<s>a</s> --> a

<s>A</s> --> A

<s>b</s> --> b

<s>B</s> --> B

</map> --> {a=A, b=B}

</set> --> null

<set>

<ref>myMap</ref> --> {a=A, b=B}

<s>c</s> --> c

<s>C</s> --> C

</set> --> null

<print>

<ref>myMap</ref> --> {a=A, b=B}

</print> --> {a=A, b=B}

<ref>myMap</ref> --> {a=A, b=B}

</block> --> {a=A, b=B}

</Rule> --> {a=A, c=C, b=B}

adimut at 2007-7-6 23:01:46 > top of Java-index,Web & Directory Servers,Directory Servers...
# 2
Job well done
Indranil_Chakraborty at 2007-7-6 23:01:46 > top of Java-index,Web & Directory Servers,Directory Servers...
# 3
Use the append tag as shown below. I hope it'll fulfill your requirement.<append name = 'myMap'><ref>myMap</ref><s>c</s><s>C</s></append>
vikasjain@sdgccom at 2007-7-6 23:01:47 > top of Java-index,Web & Directory Servers,Directory Servers...