<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 


  <xsl:include href="../../../felles/ressurser/output-method-html-v001.xsl" />

  <xsl:include href="../../../common/components/structuredtext/v002/structuredtext.xsl" />
  <xsl:include href="../../../common/components/heading/v002/heading.xsl" />  
  <xsl:include href="../../../common/components/table/v001/table.xsl"/>  

<!--
  <xsl:include href="../../../felles/komponenter/fritekst/v002/fritekst.xsl" />
  <xsl:include href="../../../felles/komponenter/tabell/v001/tabell.xsl" />
  <xsl:include href="../../../felles/komponenter/overskrift/v002/overskrift.xsl" />
-->

  <xsl:include href="../../../extensions/link-constructor-v001.xsl"/>  
  <!-- these parameters come from the url-->
  <!--<xsl:param name="current_page"/> BRUKES IKKE TIL NOE-->
  <xsl:param name="root">/vrtx/lcms/</xsl:param>

<!-- which type of quiz we are dealing with gives different feedback -->
<xsl:variable name="quiz_type" select="simple-quiz-node/question-choice/type/text()"/>

  <xsl:param name="requestParameters" />

  <xsl:variable name="section">
    <xsl:value-of select="$requestParameters/parameter[@name='section']" />
  </xsl:variable>
  <xsl:variable name="subsection">
    <xsl:value-of select="$requestParameters/parameter[@name='subsection']" />
  </xsl:variable>
  <xsl:variable name="node">
    <xsl:value-of select="$requestParameters/parameter[@name='node']" />
  </xsl:variable>


  <xsl:variable name="myself">
    <xsl:call-template name="construct-link">
      <xsl:with-param name="link-parameters-csv">section=<xsl:value-of
                                                            select="$section"/>,subsection=<xsl:value-of
                                                            select="$subsection"/>,node=<xsl:value-of select="$node"/>
                                        </xsl:with-param>
</xsl:call-template>

  </xsl:variable>


  <!-- Count the number of elements on each level, 
       depending on the parameters coming from url  --> 
  <xsl:variable name="coursename" select="concat($root, published-course/title/text())"/>

  <!-- Top level template -->
  <xsl:template match="/">
    <html>
      <head>
        <title>webleksjon | <xsl:value-of select="published-course/title/text()"/></title>
        <link rel="stylesheet">
          <xsl:attribute name="href">
            <xsl:value-of select="$root"/><xsl:text>css/uio.css</xsl:text>
          </xsl:attribute>
        </link>
        <link rel="stylesheet">
          <xsl:attribute name="href">
            <xsl:value-of select="$root"/><xsl:text>css/medark.css</xsl:text>
          </xsl:attribute>
        </link>
        <link rel="stylesheet">
          <xsl:attribute name="href">
            <xsl:value-of select="$root"/><xsl:text>css/weblesson.css</xsl:text>
          </xsl:attribute>
        </link>
        <meta name="robots" content="noindex,nofollow" />
      </head>
      
      <!-- START BODY -->
      <body>
        <table cellspacing="0" cellpadding="0" border="0" width="100%">
          <tbody>
            <tr>
              <td class="tdwidth70bgblue" valign="bottom">
                <a href="http://www.uio.no/">
                  <img width="267" height="31" class="grafikktopplogo" alt="Universitetet i Oslo" border="0">
                    <xsl:attribute name="src">
                      <xsl:value-of select="$root"/><xsl:text>images/logotopp_blaa3.gif</xsl:text>
                    </xsl:attribute>       
                  </img>
                </a>
              </td>
              <td align="right" class="topbgblue" valign="bottom"></td>
            </tr>
            <tr valign="top">
              <td align="left"><a href="#"><img class="grafikkbotnlogo" border="0" alt="Medisinske Webleksjoner" src="{$root}images/banner_webleksjon_Bokmal.gif" width="613" height="25"/></a></td>
              <td align="right" valign="middle" style="font-weight:bold;">
                <xsl:variable name="link">
                  <xsl:call-template name="construct-link" />
                </xsl:variable>
                <a href="{$link}"><xsl:value-of select="published-course/title" /></a>
              </td>
            </tr>
          </tbody>
        </table>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <col width="15%" />
          <col width="85%" />
          <tbody>
            <tr>
              <td valign="top" align="left" class="navigation">

                <table width="100%" cellpadding="2" cellspacing="2" border="0">
                  <tbody>
                    <xsl:for-each select="published-course/page">
                      <tr>
                        <td class="navsection">
          	          <xsl:variable name="section_node" select="position()"/>
                          <xsl:variable name="link">
                            <xsl:call-template name="construct-link">
                              <xsl:with-param
                              name="link-parameters-csv">section=<xsl:value-of
                              select="$section_node"/></xsl:with-param>
                            </xsl:call-template>
                          </xsl:variable>
          	          <a href="{$link}"><xsl:value-of select="title"/></a>
          	          <xsl:variable name="has_nodes" select="count(children/page)"/>

          	          <xsl:if test="$has_nodes > 0">
         		    <xsl:if test="position() = $section">            
           		      <xsl:for-each select="children/page"> 
             			<xsl:variable name="sub_node" select="position()"/>
           			<tr>
            			  <td class="navsubsection">
                                    <xsl:variable name="link">
                                      <xsl:call-template name="construct-link">
                                        <xsl:with-param name="link-parameters-csv">section=<xsl:value-of
                                          select="$section_node"/>,subsection=<xsl:value-of select="$sub_node"/>
                                        </xsl:with-param>
                                      </xsl:call-template>
                                    </xsl:variable>
          	                    <a href="{$link}"><xsl:value-of select="title"/></a>
	        		  </td>
           			</tr>  

          	                <xsl:variable name="has_sub_nodes" select="count(children/page)"/>
          	                <xsl:if test="$has_nodes > 0 and not
                                              (node = '')">
         		          <xsl:if test="position() = $subsection">            
           		            <xsl:for-each select="children/page"> 
           			      <tr>
            			        <td class="navsubsubsection">
             			          <xsl:variable name="sub_sub_node" select="position()"/>
                                    <xsl:variable name="link">
                                      <xsl:call-template name="construct-link">
                                        <xsl:with-param name="link-parameters-csv">section=<xsl:value-of
                                          select="$section_node"/>,subsection=<xsl:value-of
                                          select="$sub_node"/>
                                          ,node=<xsl:value-of select="$sub_sub_node"/>
                                        </xsl:with-param>
                                      </xsl:call-template>
                                    </xsl:variable>
          	                    <a href="{$link}"><xsl:value-of select="title"/></a>
	        		        </td>
           			      </tr>  
           		            </xsl:for-each>
           		          </xsl:if>
          	                </xsl:if>          
                                

           		      </xsl:for-each>
           		    </xsl:if>
          	          </xsl:if>          

	  	        </td>
                      </tr>
                    </xsl:for-each>       
                  </tbody>
                </table>

              </td>
              <td class="content" valign="top" align="left">
                <xsl:choose>
                  <xsl:when test="$section > 0">
                    <xsl:call-template name="render-content"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:call-template name="lesson-info"/>
                  </xsl:otherwise>
                </xsl:choose>
                
              </td>
            </tr>
          </tbody>
        </table>  
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tbody>
            <tr>
              <td class="footer" align="left" valign="bottom">
                <a class="footer" href="http://fragment.uio.no/webleksjon/">The old weblesson</a>
              </td>
              <td class="footer" align="right" valign="bottom">
                Laget av <xsl:value-of select="published-course/author"/>
              </td>
            </tr>
          </tbody>
        </table>  
      </body> 
      <!-- END BODY -->
      
    </html> 
  </xsl:template> 


  <!-- START INNHOLD -->
  <xsl:template name="render-content"> 
    <xsl:choose>
      <!-- start: nivaa 1 innhold -->
      <xsl:when test="$subsection = ''">
        <xsl:call-template name="content">
          <xsl:with-param name="element" select="published-course/page[$section = position()]" />
        </xsl:call-template>
      </xsl:when>
      <!-- slutt: nivaa 1 innhold -->
      <xsl:otherwise>
        <xsl:choose>
          <!-- start: nivaa 2 innhold -->   
          <xsl:when test="$node = ''">
            <xsl:call-template name="content">
              <xsl:with-param name="element" select="published-course/page[position() = $section]/children/page[position() = $subsection]" />
            </xsl:call-template>

          </xsl:when>
          <!-- slutt: nivaa 2 innhold --> 
          <xsl:otherwise>
            <xsl:call-template name="content">
              <xsl:with-param name="element" select="published-course/page[position() = $section]/children/page[position() = $subsection]/children/page[position() = $node]" />
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>   
    </xsl:choose>
  </xsl:template>
  <!-- SLUTT INNHOLD -->


  <xsl:template name="content">
    <xsl:param name="element" />
    <!-- Display section -->
    <div class="content">
      <h3><xsl:apply-templates select="$element/title"/></h3>
      <xsl:choose>
        <xsl:when test="$element/content">
      <br/><br/> 
      <xsl:apply-templates select="$element/content/*"/>
        </xsl:when>
        <xsl:otherwise>
<!--          <xsl:if test="$element/children/page">
            Siden har undersider
          </xsl:if>
-->        </xsl:otherwise>
      </xsl:choose>
    </div>
  </xsl:template>


  <xsl:template name="lesson-info">
    <div class="content">
      <h1><xsl:value-of select="published-course/title"/></h1>
      <h2>av <xsl:value-of select="published-course/author"/></h2>
      <p></p>
      <div class="description">
        <xsl:apply-templates select="published-course/content/*" />
      </div>
    </div>
  </xsl:template>

<!-- Start hack pga. image-node til image konvertering.

     Av en eller annen grunn oversettes image-node til image 
     og alignment til position. Dette bør endres i CoursePublisherImpl.java.
     Inntil videre duplisert og mekket på  image-node.xsl her 
     for å få caption håndtering og alignment til å virke. -->

<!--
  <xsl:template match="image-node">
    <xsl:variable name="bilde" select="url"/>
    <xsl:variable name="width" select="@width"/>
    <xsl:variable name="height" select="@height"/>
    <xsl:variable name="caption" select="caption"/>
    <img src="{$bilde}" width="{$width}" height="{$height}"/>
    <br></br>
    <div class="caption"><xsl:value-of select="$caption"/></div>
    <br></br>
  </xsl:template> 

-->
  <xsl:template match="image-node">

    <!-- Bruker variabler her også for å beholde det mest mulig likt image -->

    <xsl:variable name="url">
      <xsl:value-of select="url" />
    </xsl:variable>
 
    <!-- alt-text må ha verdi -->
    <xsl:variable name="alt-text">
      <xsl:choose>
        <xsl:when test="normalize-space(alt-text)=''">
          <xsl:value-of select="'image'" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="alt-text" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="caption">
      <xsl:value-of select="caption" />
    </xsl:variable>
  
   <xsl:variable name="alignment">
      <xsl:choose>
        <xsl:when test="@position='left'">
          <xsl:value-of select="'left'" /> 
        </xsl:when>
        <xsl:when test="@position='center'">
          <xsl:value-of select="'center'" /> 
        </xsl:when>
        <xsl:when test="@position='right'">
          <xsl:value-of select="'right'" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'left'" /><!-- venstre er default i schema -->
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
 
    <xsl:variable name="height">
      <xsl:value-of select="@height" />
    </xsl:variable>

    <xsl:variable name="width">
      <xsl:value-of select="@width" />
    </xsl:variable>
 
    <xsl:choose>
      <xsl:when test="$caption=''">
        <xsl:choose>
          <xsl:when test="$alignment='center'">
            <div style="text-align:center;">
              <img src="{$url}" alt="{$alt-text}" />
            </div>
          </xsl:when>
          <xsl:when test="$alignment='right'">
            <img style="float:right; padding:0; margin: 0 0 0 0.75em;" src="{$url}" alt="{$alt-text}" />
          </xsl:when>
          <xsl:otherwise><!-- venstre er default i schema -->
            <img style="float:left; padding:0; margin: 0 0.75em 0 0;" src="{$url}" alt="{$alt-text}" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <!-- må bruke tabell for at bildeteksten ikke skal skli ut. -->
        <!-- Evt. må høyde og bredde settes på bilde -->
        <table style="" cellspacing="0" cellpadding="0" align="{$alignment}" width="5%">
          <xsl:choose>
            <xsl:when test="$alignment='left'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0.75em 0 0'" />
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="$alignment='center'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0.75em;'" />
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="$alignment='right'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0 0 0.75em;'" />
              </xsl:attribute>
            </xsl:when>
          </xsl:choose>

          <tr>
            <td>
              <img style="margin:0; padding:0;" src="{$url}" alt="{$alt-text}">
                <xsl:if test="$height and not($height='')">
                  <xsl:attribute name="height">
                    <xsl:value-of select="$height" />
                  </xsl:attribute>
                </xsl:if>
                <xsl:if test="$width and not($width='')">
                  <xsl:attribute name="width">
                    <xsl:value-of select="$width" />
                  </xsl:attribute>
                </xsl:if>
              </img>
            </td>
          </tr>
          <tr>
            <td><xsl:apply-templates select="caption" /></td>
          </tr>
        </table>
      </xsl:otherwise>
    </xsl:choose>
      
  </xsl:template>

  <xsl:template match="image/alt-text|image/url" />

  <xsl:template match="image/caption">
    <div style="clear:both; font-size:76%; text-align:left; padding:0.5em;">
      <xsl:apply-templates />
    </div>
  </xsl:template>


  <xsl:template match="movie-node">

    <!-- Bruker variabler her også for å beholde det mest mulig likt image -->

    <xsl:variable name="url">
      <xsl:value-of select="url" />
    </xsl:variable>
 
    <!-- alt-text må ha verdi -->
    <xsl:variable name="alt-text">
      <xsl:choose>
        <xsl:when test="normalize-space(alt-text)=''">
          <xsl:value-of select="'movie'" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="alt-text" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="caption">
      <xsl:value-of select="caption" />
    </xsl:variable>
  
   <xsl:variable name="alignment">
      <xsl:choose>
        <xsl:when test="@alignment='left'">
          <xsl:value-of select="'left'" /> 
        </xsl:when>
        <xsl:when test="@alignment='center'">
          <xsl:value-of select="'center'" /> 
        </xsl:when>
        <xsl:when test="@alignment='right'">
          <xsl:value-of select="'right'" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'left'" /><!-- venstre er default i schema -->
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
 
    <xsl:variable name="height">
      <xsl:choose>
        <xsl:when test="@height=''">
          <xsl:value-of select="'256'" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@height" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="width">
      <xsl:choose>
        <xsl:when test="@width=''">
          <xsl:value-of select="'320'" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@width" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
 
    <xsl:choose>
      <xsl:when test="$caption=''">
        <xsl:choose>
          <xsl:when test="$alignment='center'">
            <div style="text-align:center;">
              <object>
                <param name="src" value="{$url}"/>
                <param name="width" value="{$width}"/>
                <param name="height" value="{$height}"/>
                <param name="controller" value="true"/>
                <param name="autoplay" value="false"/>
                <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="true"/>
              </object>
            </div>
          </xsl:when>
          <xsl:when test="$alignment='right'">
            <object style="float:right; padding:0; margin: 0 0 0 0.75em;">
              <param name="src" value="{$url}"/>
              <param name="width" value="{$width}"/>
              <param name="height" value="{$height}"/>
              <param name="controller" value="true"/>
              <param name="autoplay" value="false"/>
              <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="true"/>
            </object>
          </xsl:when>
          <xsl:otherwise><!-- venstre er default i schema -->
            <object style="float:left; padding:0; margin: 0 0.75em 0 0;">
              <param name="src" value="{$url}"/>
              <param name="width" value="{$width}"/>
              <param name="height" value="{$height}"/>
              <param name="controller" value="true"/>
              <param name="autoplay" value="false"/>
              <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="true"/>
            </object>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <!-- må bruke tabell for at bildeteksten ikke skal skli ut. -->
        <!-- Evt. må høyde og bredde settes på bilde -->
        <table style="" cellspacing="0" cellpadding="0" align="{$alignment}" width="5%">
          <xsl:choose>
            <xsl:when test="$alignment='left'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0.75em 0 0'" />
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="$alignment='center'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0.75em;'" />
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="$alignment='right'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0 0 0.75em;'" />
              </xsl:attribute>
            </xsl:when>
          </xsl:choose>

          <tr>
            <td>
              <object style="margin:0; padding:0;">
                <param name="src" value="{$url}"/>
                <param name="width" value="{$width}"/>
                <param name="height" value="{$height}"/>
                <param name="controller" value="true"/>
                <param name="autoplay" value="false"/>
                <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="false"/>
              </object>

            </td>
          </tr>
          <tr>
            <td><xsl:apply-templates select="caption" /></td>
          </tr>
<!--
          <tr>
            <td>Autoplay: <xsl:apply-templates select="autoplay" /></td>
          </tr>
-->
        </table>
      </xsl:otherwise>
    </xsl:choose>
      
  </xsl:template>

  <xsl:template match="flash-node">

    <!-- Bruker variabler her også for å beholde det mest mulig likt image -->

    <xsl:variable name="url">
      <xsl:value-of select="url" />
    </xsl:variable>
 
    <!-- alt-text må ha verdi -->
    <xsl:variable name="alt-text">
      <xsl:choose>
        <xsl:when test="normalize-space(alt-text)=''">
          <xsl:value-of select="'flash'" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="alt-text" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="caption">
      <xsl:value-of select="caption" />
    </xsl:variable>
  
   <xsl:variable name="alignment">
      <xsl:choose>
        <xsl:when test="@alignment='left'">
          <xsl:value-of select="'left'" /> 
        </xsl:when>
        <xsl:when test="@alignment='center'">
          <xsl:value-of select="'center'" /> 
        </xsl:when>
        <xsl:when test="@alignment='right'">
          <xsl:value-of select="'right'" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="'left'" /><!-- venstre er default i schema -->
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
 
    <xsl:variable name="height">
      <xsl:choose>
        <xsl:when test="@height=''">
          <xsl:value-of select="'256'" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@height" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:variable name="width">
      <xsl:choose>
        <xsl:when test="@width=''">
          <xsl:value-of select="'320'" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="@width" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
 
    <xsl:choose>
      <xsl:when test="$caption=''">
        <xsl:choose>
          <xsl:when test="$alignment='center'">
            <div style="text-align:center;">
              <object>
                <param name="src" value="{$url}"/>
                <param name="width" value="{$width}"/>
                <param name="height" value="{$height}"/>
                <param name="controller" value="true"/>
                <param name="autoplay" value="false"/>
                <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="false"/>
              </object>
            </div>
          </xsl:when>
          <xsl:when test="$alignment='right'">
            <object style="float:right; padding:0; margin: 0 0 0 0.75em;">
              <param name="src" value="{$url}"/>
              <param name="width" value="{$width}"/>
              <param name="height" value="{$height}"/>
              <param name="controller" value="true"/>
              <param name="autoplay" value="false"/>
              <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="false"/>
            </object>
          </xsl:when>
          <xsl:otherwise><!-- venstre er default i schema -->
            <object style="float:left; padding:0; margin: 0 0.75em 0 0;">
              <param name="src" value="{$url}"/>
              <param name="width" value="{$width}"/>
              <param name="height" value="{$height}"/>
              <param name="controller" value="true"/>
              <param name="autoplay" value="false"/>
              <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="false"/>
            </object>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <xsl:otherwise>
        <!-- må bruke tabell for at bildeteksten ikke skal skli ut. -->
        <!-- Evt. må høyde og bredde settes på bilde -->
        <table style="" cellspacing="0" cellpadding="0" align="{$alignment}" width="5%">
          <xsl:choose>
            <xsl:when test="$alignment='left'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0.75em 0 0'" />
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="$alignment='center'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0.75em;'" />
              </xsl:attribute>
            </xsl:when>
            <xsl:when test="$alignment='right'">
              <xsl:attribute name="style">
                <xsl:value-of select="'border: 1px solid #666; padding:0; margin:0 0 0 0.75em;'" />
              </xsl:attribute>
            </xsl:when>
          </xsl:choose>

          <tr>
            <td>
              <object style="margin:0; padding:0;">
                <param name="src" value="{$url}"/>
                <param name="width" value="{$width}"/>
                <param name="height" value="{$height}"/>
                <param name="controller" value="true"/>
                <param name="autoplay" value="false"/>
                <embed controller="true" src="{$url}" width="{$width}" height="{$height}" autoplay="false"/>
              </object>

            </td>
          </tr>
          <tr>
            <td><xsl:apply-templates select="caption" /></td>
          </tr>
<!--
          <tr>
            <td>Autoplay: <xsl:apply-templates select="autoplay" /></td>
          </tr>
-->
        </table>
      </xsl:otherwise>
    </xsl:choose>
      
  </xsl:template>

<!-- Slutt hack pga. image-node  til image konvertering -->



<!-- QUIZ -->

<xsl:template match="simple-quiz">
  <xsl:variable name="answered">
    <xsl:value-of select="$requestParameters/parameter[@name='answered']" />
  </xsl:variable>

<xsl:choose>
<xsl:when test="not($answered = '')">
  <xsl:apply-templates select="*" mode="answered" />
</xsl:when>
<xsl:otherwise>
  <form action="{$myself}" method="POST">
        <xsl:apply-templates />
  	<input type="submit" name="answered" value="Svar"/>
  </form>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="number-of-questions|ordering|quiz-mode">
</xsl:template>

<xsl:template match="question-choice">
  <xsl:variable name="qNumber" select="count(preceding-sibling::*)" />
   	<br/>
   	<br/>
   	<h4><xsl:apply-templates select="title/text()"/></h4>
   	<p>
   	<xsl:apply-templates select="content/*"/>
   	</p>
   	<p>
   	<h3><xsl:apply-templates select="instruction/text()"/></h3>
   	</p>
  	<p>

  <!-- løsninga for denne quizen er basert på askmode=together og response=digest -->
  <!-- type er enten multiselect eller singleselect -->
  <xsl:variable name="type" select="type/text()"/>
  <xsl:choose>  
  	<xsl:when test="$type='single-select'">
  		<!-- dette er singleselect -->
  		<xsl:for-each select="alternatives/answer">
                  <xsl:variable name="name" select="'q' + qNumber +
    	   			'a' + count(preceding-sibling::*)" />
    	   			<xsl:variable name="q" select="response/text()"/>
    	   		    <label><input type="radio" name="{$name}" value="radio"/><xsl:value-of select="$q"/></label>
    			<br/>
    	 </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
    	<xsl:for-each select="alternatives/answer">
    	   			<xsl:variable name="q" select="response/text()"/>
    	   		    <label><input type="checkbox" name="test" value="checkbox"/><xsl:value-of select="$q"/></label>
    			<br/>
    	 </xsl:for-each>
    </xsl:otherwise>
   </xsl:choose>
   </p>
</xsl:template>

<xsl:template match="question-open">
   	<br/>
   	<br/>
   	<h4><xsl:apply-templates select="title/text()"/></h4>
   	<p>
   	<xsl:apply-templates select="content/*"/>
   	</p> 
   	<p>
   	<xsl:apply-templates select="instruction"/><br/>
   	<!-- her skal vortex egen løsning av textareas brukes.. -->
   	<textarea name="textarea" cols="40" rows="10"></textarea>   	
   	</p>   	
</xsl:template>


<!-- Quiz answer -->

<xsl:template match="question-choice" mode="answered">
   	<br/>
   	<h4><xsl:apply-templates select="title/text()"/></h4>
   	<p>
   	<xsl:apply-templates select="content/*"/>
   	</p>
   	<p>
	<xsl:apply-templates select="alternatives"/> 	
	</p>
</xsl:template>

<xsl:template match="question-open" mode="answered">
   	<br/>
   	<h4><xsl:apply-templates select="title/text()"/></h4>
   	<p>
   	<xsl:apply-templates select="content/*"/>
   	</p>
   	<p>
	<xsl:apply-templates select="feedback"/> 	
	</p>
</xsl:template>

<xsl:template match="alternatives">
	<xsl:for-each select="answer">
		<xsl:variable name="user-response" select="user-response"/>
		<xsl:variable name="answer" select="position()"/>
		<xsl:variable name="validity" select="validity/text()"/>
		<xsl:variable name="response" select="response/text()"/>
		<xsl:variable name="begrunnelse" select="feedback/paragraph/text()"/>
		<!-- type er enten multiselect eller singleselect -->
		<xsl:choose>
  		<xsl:when test="$quiz_type='single-select'">		
			<xsl:if test="$user-response='1'">
				<p>
   					<b>Ditt svar:</b> <xsl:value-of select="$response"/>
				</p>
   				<p>
   					<xsl:choose>
   					 <xsl:when test="$validity='1'">
   						Dette er riktig!
   					 </xsl:when>
   					 <xsl:when test="$validity='0'">
   						Dette er feil!
   					 </xsl:when>
   					</xsl:choose>
   				</p>	
   				<p>
   				   	<b>Begrunnelse:</b> <xsl:value-of select="$begrunnelse"/>
   				</p>
				<br/>
			</xsl:if>
		</xsl:when>
  		<xsl:when test="$quiz_type='multi-select'">			
  		
		<xsl:choose>
			<xsl:when test="$user-response='1' and $validity='1'">
				<p>
   					Dette svaret valgte du <b>(riktig)</b>: <xsl:value-of select="$response"/>
				</p>	
   				<p>
   				   	<b>Begrunnelse: </b><xsl:value-of select="$begrunnelse"/>
   				</p>
				<br/>
			</xsl:when>		
			<xsl:when test="$user-response='0' and $validity='1'">
				<p>
   					Dette rette svaret valgte du ikke <b>(feil)</b>: <xsl:value-of select="$response"/>
				</p>	
   				<p>
   				   	<b>Begrunnelse: </b><xsl:value-of select="$begrunnelse"/>
   				</p>
				<br/>
			</xsl:when>
			<xsl:when test="$user-response='1' and $validity='0'">
				<p>
   					Dette svaret valgte du <b>(feil)</b>: <xsl:value-of select="$response"/>
				</p>	
   				<p>
   				   	<b>Begrunnelse: </b><xsl:value-of select="$begrunnelse"/>
   				</p>
				<br/>
			</xsl:when>			
		</xsl:choose>		
		
		</xsl:when>
		</xsl:choose>
		</xsl:for-each>
</xsl:template>







</xsl:stylesheet>
