[xsl] recursion multiple cells

Subject: [xsl] recursion multiple cells
From: "Markus Hanel" <markus.hanel@xxxxxx>
Date: Wed, 3 Dec 2003 16:20:19 +0100 (MET)
Hello,
I'm having a little trouble with recursion and can use some guidance please.
I have a matrix of a optional number of columns and rows. The question in
this example has two answers. (xml see below) The first answer is the solution
in the first cell, and the second answer is the solution in the second cell
of a row. The student can write the answer in a optional row. It must not the
row where the valid_input is. I had to compare the first solution
"Vorarlberg" with the valid_input of the first cell in the first row, the second row,
and so on.  At this example "Vorarlberg" is right at the second row: Now i had
to compare the second answer "Bregenz" in the second cell of the actual row.
Is the first answer right i had to sum the points of the first solution, is
the second answer right I had to do the same. And so on with the answer
"Tirol. The output at the end is the sum of the points of the right answer.
I have tried and solved the problem when the right answer stands in the
right row (see xsl below). But the studends can write the answers in a optional
row.
Many thanks, Markus

<xsl:template match="MultipleAnswer" mode="eval">
  <xsl:call-template name="sum_rows" />
</xsl:template>

<xsl:template name="sum_rowsm">
<xsl:param name="i" select="count(table/row)" />
<xsl:param name="rows" select="0" />
<xsl:choose>
  <xsl:when test="$i &gt; 0">
    <xsl:variable name="cols">
      <xsl:call-template name="sum_cols">
        <xsl:with-param name="i" select="$i" />
      </xsl:call-template>
    </xsl:variable>
    <xsl:call-template name="sum_rows">
      <xsl:with-param name="rows" select="$rows + $cols" />
      <xsl:with-param name="i" select="$i - 1" />
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <td><xsl:value-of select="$rows" /></td>
  </xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template name="sum_colsm">
<xsl:param name="j" select="count(table/row/child::*)" />
<xsl:param name="i" />
<xsl:param name="sum" select="0" />

<xsl:choose>
  <xsl:when test="$j &gt; 0">
  <xsl:variable name="point"
select="count(table/row[$i]/cell[$j]/solution/valid_input[./text()=../text()])" />
    <xsl:variable name="points">
      <xsl:choose>
        <xsl:when test="$point &gt; 0">
          <xsl:value-of select="table/row[$i]/cell[$j]/solution/@points" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:call-template name="sum_cols">
      <xsl:with-param name="i" select="$i" />
      <xsl:with-param name="j" select="$j - 1" />
      <xsl:with-param name="sum" select="$sum + $points" />
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="$sum" />
  </xsl:otherwise>
</xsl:choose>
</xsl:template>

<MultipleAnswer>
<notice>Die Reihenfolge der Eingabe spielt keine Rolle!</notice>
<question>Nenne alle Österreichischen Bundesländer und deren
Hauptstädte!</question>
<table>
  <column>Bundesland</column>
  <column>Hauptstadt</column>
  <row number="1">
    <cell>
      <solution type="text"
points="0">Tirol<valid_input>Vorarlberg</valid_input><valid_input>Tirol</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="1">Bregenz<valid_input>Innsbruck</valid_input></solution>
    </cell>
  </row>
  <row number="2">
    <cell>
      <solution type="text"
points="2">Tirol<valid_input>Vorarlberg</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="3">Innsbruck<valid_input>Bregenz</valid_input></solution>
    </cell>
  </row>
  <row number="3">
    <cell>
      <solution type="text"
points="4">Salzburg<valid_input>Salzburg</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="5">Salzburg<valid_input>Salzburg</valid_input></solution>
    </cell>
  </row>
  <row number="4">
    <cell>
      <solution type="text"
points="6">Oberösterreich<valid_input>Oberösterreich</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="7">Linz<valid_input>Linz</valid_input></solution>
    </cell>
  </row>
  <row number="5">
    <cell>
      <solution type="text"
points="8">Niederösterreich<valid_input>Niederösterreich</valid_input></solution>
    </cell>
    <cell>
      <solution type="text" points="9">Sankt Pölten<valid_input>Sankt
Pölten</valid_input></solution>
    </cell>
  </row>
  <row number="6">
    <cell>
      <solution type="text"
points="10">Wien<valid_input>Wien</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="11">Wien<valid_input>Wien</valid_input></solution>
    </cell>
  </row>
  <row number="7">
    <cell>
      <solution type="text"
points="12">Burgenland<valid_input>Burgenland</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="13">Eisenstadt<valid_input>Eisenstadt</valid_input></solution>
    </cell>
  </row>
  <row number="8">
    <cell>
      <solution type="text"
points="14">Steiermark<valid_input>Steiermark</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="15">Graz<valid_input>Graz</valid_input></solution>
    </cell>
  </row>
  <row number="9">
    <cell>
      <solution type="text"
points="16">Kärnten<valid_input>Kärnten</valid_input></solution>
    </cell>
    <cell>
      <solution type="text"
points="17">Klagenfurt<valid_input>Klagenfurt</valid_input></solution>
    </cell>
  </row>
</table>
</MultipleAnswer>

-- 
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread