Search code examples
xmlif-statementantant-contribxmltask

ant xmltask node if


my new problem is an if condition tags .

In fact, I can not get into the condition 'then' when "param" is 0.

<xmltask source="rapport.xml">                                      
    <call path="//testsuites">
        <param name="chaine" path="@name"/>
        <param name="testsuite1" path="testsuite[1]/@name"/>
        <param name="testsuite2" path="testsuite[2]/@name"/>                                
        <param name="ko1" path="count(testsuite[1]/testcase/failure[@type='ko'])"/>
        <actions>   
            <echo message="count fichiers ko 1 : @{ko1}"/>
            <if>
                <equals arg1="${ko1}" arg2="0" />
                <then>
                    <echo message="OK"/>
                </then>
                <else>                              
                    <echo message="KO"/>                            
                </else>
            </if>                           
        </actions>
    </call>                               
</xmltask>

Why I can not get into the "then" condition, but only in "else" while "arg1" = 0 ?

The rapport.xml is :

<testsuites name="COMPTES" tests="6" time="7" timestamp="2014-07-01T17-20-07" failures="6" errors="0">
    <testsuite name="100" tests="6" failures="6" errors="0" time="7">
        <testcase classname="Script.COMPTES.100" name="TEST1" time="1">
            <failure message="Not exist file or counter or used" type="fichiersInexistants">
                File No matches
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.100" name="TEST2" time="2">
            <failure message="Not exist file or counter or used" type="fichiersUtilises">
                Data set in use
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.100" name="TEST3" time="3">
            <failure message="Not exist file or counter or used" type="fichiersInexistants">
                File No matches
            </failure>
        </testcase>
        <testcase classname="Script.COMPTES.100" name="TEST4" time="3">
            <failure message="File abended" type="abended">
                File abended
            </failure>
        </testcase>
    </testsuite>
</testsuites>

Solution

  • Try using @{ko1} instead of ${ko1} to reference the parameter. If the echo is really printing 0, it should work.

    <echo message="count fichiers ko 1 : @{ko1}"/>
    <if>
        <equals arg1="@{ko1}" arg2="0" />