I have two nant properties called server and letter that has stings in its value. The goal is to associate the first value of the first string with the first value of the second, and the 2nd value in the first with the 2nd value in the second string. Here is what I have tried.
<property name="server" value="server1;server2"/>
<property name="letter" value="A;B/>
<foreach item="String" in="${server}" delim=";" property="server">
<foreach item="String" in="${letter}" delim=";" property="letter">
<xmlpoke file="${server}\xml.config" xpath="//@path" value="${letter}" />
</foreach>
<foreach>
The above results will basically both server 1 and 2 with the letter B value. But really server 1 should have value A and Server 2 have value B. How can this be handled in Nant? Thanks in advance.
Adding a couple of properties to count how far you are through the loops should help here:
<property name="server" value="server1;server2" />
<property name="letter" value="A;B" />
<!-- Start at 0 for the server loop -->
<property name="counter.server" value="0" />
<foreach item="String" in="${server}" delim=";" property="server">
<!-- reset the letter counter back to 0 for each server loop -->
<property name="counter.letter" value="0" />
<foreach item="String" in="${letter}" delim=";" property="letter">
<if test="${counter.server == counter.letter}">
<!-- perform the task if we're at the same point in both loops -->
<xmlpoke file="${server}\xml.config" xpath="//@path" value="${letter}" />
</if>
<!-- increment letter count -->
<property name="counter.letter" value="${int::parse(counter.letter)+1}" />
</foreach>
<!-- increment server count -->
<property name="counter.server" value="${int::parse(counter.server)+1}" />
<foreach>
This will handle the case where the properties don't have a matching number of items - it will silently ignore them.