Menu

if statement problem

Help
2013-09-21
2013-09-21
  • Henry Salom

    Henry Salom - 2013-09-21

    Hi,

    I hope someone can help. I am trying to build a delimited list (delimited by |) to a temporary file with the following code:

    <loop item="professionList" index="j">
    <list>
    <xpath expression="(//div&lt;span&gt;[@class='categories']&lt;/span&gt;//li/text())">

    </xpath>
    </list>
    <body>

                        <file action="append" type="text" path="professionList.txt">                            
                            <template>
                                <case>
                                    <if condition="${j = 1}">
                                        ${professionList}
                                    </if>
                                    <else>
                                        ${professionList}
                                    </else>
                                </case>
                            </template>
                        </file>
                    </body>
                </loop>
    

    The problem that I'm having is that the if condition determined by the loop counter j always branches to else even though as I understand this the first pass through the loop should match ${j = 1}. Can someone please explain why?

     
  • Henry Salom

    Henry Salom - 2013-09-21

    Found a soultion to my problem by capturing the count of list items in a separate var and then comparing to the loop index var using the toInt() method on both the count of list items var and the loop index var.

    <case>
        <if condition="${ListCount.toInt() != j.toInt()}">
            ${List}|
        </if>
        <else>
            ${List}
        </else>
    </case>
    
     

Log in to post a comment.