3.5. Xdefinition designed to combine both modes

<xd:def xmlns:xd="http://www.xdef.org/xdef/4.2"
        xd:name="WeatherDisplay" xd:root="Weather" >

  <xd:declaration> float sum = 0; int num = 0; </xd:declaration>

  <Weather xd:script="finally returnElement(xcreate('html'));"
           date="optional date();" >
    <Measurement xd:script="occurs *;" 
       temperature="float(-30.0, +50.0); /*limits of values*/ onTrue {num++; sum = parseFloat(getText());}"
       wind       ="float();"
       time       = "time();" />
  </Weather>

  <html>
    <h2> create 'Weather on ' + from('@date'); </h2>
    /* Note all elements "li" are created from elements "Measurement" */
    <li xd:script="occurs *; create from('Measurement');" >
      create 'Time: ' + from('@time')‏ + ', wind: ' + from('@wind')‏ + ', temperature: ' + from('@temperature')‏;
    </li>
    <h3> /* Create the text with number of measurements and the average of measured temperatures */
      create num == 0 ? 'No measurements' : format('Average temperature: %2.1f', sum/num));
    </h3>
  </html>

</xd:def>
You can try it HERE