untitled

(ff) #1

11.7 Procedural Programming 277






The name of the procedure isvariance. The set of elements to be used
for the computation is calledelements. The accumulator isssqand the
iterator isi. The second step is to write the procedure body. This consists of
a conditional element for the two cases. It looks like this:


<xsl:choose>
<xsl:when test="$i > count($elements)">
<!-- The final computation goes here. -->
</xsl:when>
<xsl:otherwise>
<!-- The computation on each subelement goes here. -->
</xsl:otherwise>
</xsl:choose>

Since the iterator starts at 1, the computation is complete when the iterator
exceeds the total number of elements to be processed. It does not matter
whether the final computation is written first or second. So it could also be
written this way:


<xsl:choose>
<xsl:when test="$i <= count($elements)">
<!-- The computation on each subelement goes here. -->
</xsl:when>
<xsl:otherwise>
<!-- The final computation goes here. -->
</xsl:otherwise>
</xsl:choose>

The computation on each subelement consists of three steps:



  1. Add the next square to the accumulator.

  2. Increase the iterator by 1.

  3. Continue the computation.


Here is the program:

Free download pdf