2.8. Declaration of variables, methods and types

Variables, methods and types of values used in the script you can describe in the element <xd:declaration> in a X-Definition:
<xd:def xmlns:xd="http://www.xdef.org/xdef/3.2" name="Example" root="Measurements" >

<xd:declaration>
   int num = 0; /* Number of measurements. */
   float sum = 0.0; /* Sum of temperatures used for calculation of average. */
   /* Type of value of temperature (Celsius degree).*/
   type temperature double(-283.149806372, 10e4);
</xd:declaration>

<Measurements xd:script="finally outln('Number of measurements: ' + num + ', average: ' + sum/num);" >
    <Temperature xd:script = "occurs +;">
      <xd:text> temperature(); onTrue { num++; sum += getParsedFloat(); }; </xd:text>
    </Temperature>
</Measurements>

</xd:def>
You can try it HERE.
Prev Content Next