<?xml version="1.0" encoding="ISO-8859-1"?>
<!--DocuML 3.0 2002 by usegroup, jstaerk@usegroup.de
changes in v2: 	-changed from proprietary format to XSLT
changes in v3: 	-exercises
		-variables in project.xml, not hard-coded in XSL-file
-->
<xsl:stylesheet version="1.1"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/TR/REC-html40">

<xsl:include href="xhtmlxsl.xsl"/>
<xsl:output method="html"
  doctype-public="-//W3C/DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
  />

<xsl:template match="/">

<!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">-->

		<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
		<!-- v2.00: Einfuehrung in PHP (http://www.usegroup.de/software/) -->
		<head>
		<title><xsl:value-of select="article/@name"/> (<xsl:value-of select="document('project.xml')//variables/title/@value"/>) </title>
		<meta name="description" content="{document('project.xml')//variables/title/@value}"/>
		<xsl:variable name="keywordsStr">
		  <xsl:for-each select="document('project.xml')//variables/keyword"><xsl:value-of select="@value"/>,</xsl:for-each>
		</xsl:variable>
		<meta name="keywords" content="{$keywordsStr}{//article/@name}"/>
		<style type="text/css">
			p {text-align:justify;alignment:justify; columns:2;}
			h1 {font-family:"arial,helvetica";}
			td {font-family:"arial,helvetica;"}
			td.nav {font-family:"arial,helvetica;"; font-size:9pt;}
		</style>
		</head>
		<body bgcolor="#FFFFFF" text="#000000" link="#AA5522" vlink="#772200" alink="#000000">

	<xsl:call-template name="navbar"/>
 	<xsl:if test="not(document('project.xml')//project/settings//set[@print='true'])">
		<xsl:call-template name="navfiles"/>
	</xsl:if>

	<xsl:apply-templates select="*[not(self::s)]"/> 	<!-- step1: zuerst alle ausser ps prozessieren damit links vor den ps stehen können -->
	<xsl:apply-templates select="s"/>

<!--	<xsl:value-of select="article"/> -->
	<xsl:if test="document('project.xml')//project/settings//set[@print='true']">
		<xsl:call-template name="printAnswers"/>
	</xsl:if>
	<xsl:if test="isPrintVersion">
	ISPRINT
		<xsl:call-template name="printAnswers"/>
	</xsl:if>

 	<xsl:if test="not(document('project.xml')//project/settings//set[@print='true'])">
		<xsl:call-template name="navfiles"/>
	</xsl:if>
	<xsl:call-template name="navbar"/>

				<a name="bottom"></a>

		</body>
		</html>
   </xsl:template>

	<xsl:template name="printAnswers">
		<xsl:if test="//exercise">
		<p/>
		&#xA0;
		<p/>
		<table width="100%">
		<tr>
		<td bgcolor="#A0A0A0" width="100%">
		<xsl:for-each select="//exercise">
			Lösung Aufgabe <xsl:value-of select="count(preceding-sibling::exercise)+1"/>:
			<xsl:variable name="answerString">
				<xsl:for-each select="answer"><xsl:value-of select="@correct"/>,</xsl:for-each>
			</xsl:variable>
			<xsl:value-of select="substring($answerString,0,string-length($answerString))"/>
			<br/>
		</xsl:for-each>
		</td>
		</tr>
		</table>
		</xsl:if>

	</xsl:template>
	<xsl:template name="navbar"><!-- möglichkeit, zu anderen datein zu wechseln, am Beginn und Ende der Seite aufzurufen -->
		<table cellpadding="4" cellspacing="0" border="0" width="100%">
		<tr>
			<td bgcolor="#FFEEDD" class="nav">
				<a name="top">
					<img src="img/ordner.gif" width="16" height="13" border="0"/>
				</a>
				<a href="{document('project.xml')//variables/upmost/@href}">
					<b><xsl:value-of select="document('project.xml')//variables/upmost/@value"/></b>
				</a>
				<img src="img/ordner.gif" width="16" height="13" border="0"/>
				<a href="index.html"><b><xsl:value-of select="document('project.xml')//variables/title/@value"/></b></a>
				<img src="img/ordner.gif" width="16" height="13" border="0"/><b>
				<!--xsl:param name="name"/-->
				<xsl:value-of select="//article/@name"/>
			</b></td>
			<td bgcolor="#FFEEDD" align="right" valign="bottom"><div style="font-size:6pt;font-family:arial,helvetica;">
			<xsl:if test="document('project.xml')//variables/licenselink/@href">
			<a href="{document('project.xml')//variables/licenselink/@href}">copyright (c)</a>
			</xsl:if>
			<xsl:if test="not(document('project.xml')//variables/licenselink/@href)">
			copyright (c)
			</xsl:if>

			<xsl:value-of select="document('project.xml')//variables/copyrightlink/@year"/> &#xA0; <a href="{document('project.xml')//variables/copyrightlink/@href}"><xsl:value-of select="document('project.xml')//variables/copyrightlink/@value"/></a></div></td>
		</tr>
		</table>

	</xsl:template>

	<xsl:template name="changeextension">
	<xsl:param name="name"/>
	<xsl:if test="substring-before($name, '.xml')">
		<xsl:value-of select="concat(substring-before($name, '.xml'), '.html')"/>
	</xsl:if>
	</xsl:template>

	<xsl:template name="navfiles"><!-- zeigt die nächste/vorherige datei  -->
		<table cellpadding="4" cellspacing="0" border="0" width="100%">
		<tr>
				<xsl:variable name="tid">
				<xsl:value-of select="/article/@id"/>
				</xsl:variable>
				<xsl:variable name="previous">
					<xsl:for-each select="document('project.xml')//file[@id=$tid]">
					<xsl:call-template name="changeextension">
					<xsl:with-param name="name" select="preceding-sibling::file[position()=1]/@name"/>
					</xsl:call-template>
					</xsl:for-each>
				</xsl:variable>
				<xsl:variable name="previousname">
					<xsl:for-each select="document('project.xml')//file[@id=$tid]">
					<xsl:value-of select="document(preceding-sibling::file[position()=1]/@name)/article/@name"/>
					</xsl:for-each>

				</xsl:variable>
				<xsl:variable name="next">
					<xsl:for-each select="document('project.xml')//file[@id=$tid]">
					<xsl:call-template name="changeextension">
					<xsl:with-param name="name" select="following-sibling::file[position()=1]/@name"/>
					</xsl:call-template>
					</xsl:for-each>
				</xsl:variable>
				<xsl:variable name="nextname">
					<xsl:for-each select="document('project.xml')//file[@id=$tid]">
					<xsl:value-of select="document(following-sibling::file[position()=1]/@name)/article/@name"/>
					</xsl:for-each>

				</xsl:variable>
			<td align="left" bgcolor="#FFEEDD" width="33%" class="nav">
			<xsl:if test="$previous!=''">
				<a href="{$previous}"><img border="0" src="img/links.gif"/><xsl:value-of select="$previousname"/></a>
			</xsl:if>
			&#160; <!-- &nbsp; for netscape to show this column-->
			</td>
			<td align="center" bgcolor="#FFEEDD" width="33%" class="nav">
			<b><xsl:value-of select="/article/@name"/></b>
			</td>
			<td align="right" bgcolor="#FFEEDD" width="33%" class="nav">
			&#160; <!-- &nbsp; for netscape to show this column-->
			<xsl:if test="$next!=''">
				<a href="{$next}"><xsl:value-of select="$nextname"/><img border="0" src="img/rechts.gif"/></a>
			</xsl:if>
			</td>
		</tr>
		</table>

	</xsl:template>

   <xsl:template match="links">

   		<table width="100%" border="0">
   		<td>

		<img src="{document('project.xml')//variables/logo/@src}" border="0" align="left" alt="{document('project.xml')//variables/logo/@alt}"/>
		</td>
		<td align="left">
		<h2><xsl:value-of select="document('project.xml')//variables/author/@value"/><br/><xsl:value-of select="document('project.xml')//variables/title/@value"/><br/><xsl:value-of select="//article/@name"/></h2>
				<p>

	<!-- <xsl:apply-templates/> 	um article/@name schreiben zu koennen -->

					<xsl:for-each select="//s">
					<img src="img/unten.gif" width="14" height="10" border="0" alt="nach unten"/>
					<a href="#{@a}"><xsl:value-of select="@name"/></a>

					<br/>


					</xsl:for-each>



				</p>
		</td>
		</table>
   </xsl:template>


<xsl:template match="s">
        <a name="{@a}"/>

	<!--<xsl:apply-templates/> -->
	<h2><xsl:value-of select="@name"/><div style="color:#0000ff;font-size:10pt;"><xsl:value-of select="@sub"/></div></h2>
			<table bgcolor="#EEEEEE" width="100%"><tr><td><a href="#top"><img src="img/oben.gif" width="14" height="10" border="0" alt="nach oben"/></a><a href="#bottom">

			<xsl:if test="position()!=last()">
			<img src="img/unten.gif" alt="{@name}" border="0"/>
			</xsl:if>


			</a>&#160;</td></tr></table>






				<p> <xsl:apply-templates/> </p><br/>



   </xsl:template>

   <xsl:template match="downloadlink">
   	<xsl:if test="document('project.xml')//project/settings//set[@online='true']">
		<a href="{document('project.xml')//variables/download/@href}">Download</a> dieses Tutorials
	</xsl:if>
   </xsl:template>

<xsl:template match="listref"> <!-- step3: stichwortverzeichnis-->
  <a href="#nachstichwort"><img src="img/unten_stichwort.gif" border="0"/></a><xsl:text> </xsl:text><a href="#nachdatei"><img src="img/unten_datei.gif" border="0"/></a>
  <xsl:variable name="nodetree">
  <xsl:for-each select="document('project.xml')//file"> <!-- document(document('project.xml')//file/@name)//reference -->
        <xsl:variable name="filename">
         <xsl:call-template name="changeextension">
         <xsl:with-param name="name" select="@name"/>
         </xsl:call-template>
        </xsl:variable>

        <xsl:if test="contains (@name, '.xml')"><!-- only look in xml files for cues -->
	<file xmlns="" name="{$filename}">
			<xsl:copy-of select="document(@name)//s"/>
	</file>
  	</xsl:if>

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

  <a name="nachstichwort">  </a>
  <h2>Nach Stichwort</h2>

  <xsl:for-each select="$nodetree//reference">
    <xsl:sort select="@name"/>
    <a href="{../../@name}#{../@a}"><xsl:value-of select="@name"/></a><br/>
  </xsl:for-each>


  <a name="nachdatei">  </a>
  <a href="#top"><img src="img/oben_anfang.gif" border="0" align="right"/></a>
  <h2>Nach Datei</h2>
  <xsl:for-each select="$nodetree//file">
  <xsl:sort select="@name"/>
    <xsl:if test="s//reference">
      <a href="{@name}"><h3><xsl:value-of select="@name"/></h3></a>
    </xsl:if>
	<xsl:for-each select="s//reference">
	  <xsl:sort select="@name"/>
	    <a href="{../../@name}#{../@a}"><xsl:value-of select="@name"/></a><br/>
    	</xsl:for-each>
  </xsl:for-each>

  <a href="#top"><img src="img/oben_anfang.gif" border="0" align="right"/></a>
   </xsl:template>

<xsl:template match="listtoc">
  <h1>Inhalt:</h1><br/>
  <table width="100%">

  <xsl:for-each select="document('project.xml')//file">
  	<xsl:variable name="filename">
	<xsl:choose>
	<xsl:when test="contains(@name, '.html')">
	        <xsl:value-of select="@name"/>
	</xsl:when>
	<xsl:otherwise>
         	<xsl:call-template name="changeextension">
         	<xsl:with-param name="name" select="@name"/>
         	</xsl:call-template>
	</xsl:otherwise>
	</xsl:choose>
	</xsl:variable>
  <tr>
  <td width="10%">
  </td>
  <td width="1%">
			<xsl:number/>
  </td>
  <td width="*" background="img/punkt.gif"> </td>
  <td width="80%">

			<a href="{$filename}">
  			<xsl:value-of select="document(@name)//@name"/>
  			</a>
  </td>
  </tr>

   </xsl:for-each>

  </table>

   </xsl:template>

  <xsl:template match="example|ex">
  <pre>
	<xsl:value-of select="."/>
  </pre>

   </xsl:template>

  <xsl:template match="dmltable">
	<table border="0" width="80%" cellspacing="1" cellpadding="3">
	<xsl:apply-templates/>
	</table>
  </xsl:template>

  <xsl:template match="dmlrow">
	<tr>
	<xsl:apply-templates/>
	</tr>
  </xsl:template>

  <xsl:template match="dmlcol">

  	<xsl:choose>
  	<xsl:when test="@colspan and @rowspan">
	<td bgcolor="#F0F0F0" colspan="{@colspan}" rowspan="{@rowspan}">
	<xsl:apply-templates/>
	</td>
	</xsl:when>
  	<xsl:when test="@colspan">
	<td bgcolor="#F0F0F0" colspan="{@colspan}">
	<xsl:apply-templates/>
	</td>
	</xsl:when>
  	<xsl:when test="@rowspan">
	<td bgcolor="#F0F0F0" rowspan="{@rowspan}">
	<xsl:apply-templates/>
	</td>
	</xsl:when>
  	<xsl:otherwise>
	<td bgcolor="#F0F0F0">
	<xsl:apply-templates/>
	</td>
  	</xsl:otherwise>
	</xsl:choose>
  </xsl:template>

  <xsl:template match="exercise">
  <br/>Aufgabe <xsl:value-of select="count(preceding-sibling::exercise)+1"/>:<br/>
  <xsl:variable name="randomid">
    <xsl:value-of select="generate-id()"/>
  </xsl:variable>
  <xsl:variable name="typeToCompare">
	<xsl:choose>
		<xsl:when test="@type='multiplechoice'">.checked</xsl:when>
		<xsl:when test="@type='gaptext'">.value</xsl:when>
		<xsl:otherwise>.value</xsl:otherwise>
	</xsl:choose>
  </xsl:variable>
  <xsl:variable name="typeBracket">
	<xsl:choose>
		<xsl:when test="@type='multiplechoice'"></xsl:when>
		<xsl:when test="@type='gaptext'">&quot;</xsl:when>
		<xsl:otherwise></xsl:otherwise>
	</xsl:choose>
  </xsl:variable>

  <script>
	function func<xsl:value-of select="$randomid"/>()
	{
		<xsl:variable name="condition">
		<xsl:for-each select="answer">
			document.<xsl:value-of select="$randomid"/>.elements[<xsl:value-of select="count(preceding-sibling::answer)"/>]<xsl:value-of select="$typeToCompare"/>==<xsl:value-of select="$typeBracket"/><xsl:value-of select="@correct"/><xsl:value-of select="$typeBracket"/>
		&amp;&amp;</xsl:for-each>
		</xsl:variable>
  		if ( <xsl:value-of select="substring($condition,0,string-length($condition)-2)"/>
		) alert("Die Antwort ist korrekt!");

		<xsl:variable name="elseStr">
		<xsl:for-each select="answer">
			<xsl:variable name="messageToShow">
				<xsl:choose>
					<xsl:when test="../hint"><xsl:value-of select="../hint"/></xsl:when>
					<xsl:when test="@hint"><xsl:value-of select="@hint"/></xsl:when>
					<xsl:otherwise>Die Antwort ist leider NICHT korrekt.</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>


			else if (document.<xsl:value-of select="$randomid"/>.elements[<xsl:value-of select="count(preceding-sibling::answer)"/>]<xsl:value-of select="$typeToCompare"/>!=<xsl:value-of select="$typeBracket"/><xsl:value-of select="@correct"/><xsl:value-of select="$typeBracket"/>)
			alert("<xsl:value-of select="$messageToShow"/>");
		</xsl:for-each>
		</xsl:variable>
		<xsl:value-of select="substring($elseStr,4)"/>
		}
	</script>
	<br/>

	<form name="{$randomid}" onSubmit="return false;">

<!--	  <xsl:apply-templates/>--> <!--select="*[not(self::question)]"-->
<!--	  <xsl:apply-templates select="text()|*"/>-->
	  <xsl:value-of select="question"/>
	  <xsl:if test="@clue='true'">
	    <xsl:if test="@type='multiplechoice'">
	    (<xsl:value-of select="count(answer[@correct='true'])"/>)
	    </xsl:if>
	  </xsl:if>
	  <xsl:apply-templates select="text()|*[not(self::question|self::hint)]"/>
	<br/>
 	<xsl:if test="not(document('project.xml')//project/settings//set[@print='true'])">
		<input type="submit" value="überprüfen" onClick="func{$randomid}()"/>
	</xsl:if>
	</form>

  </xsl:template>

  <xsl:template match="answer">
	<xsl:variable name="typeToShow">
		<xsl:choose>
			<xsl:when test="../@type='multiplechoice'">checkbox</xsl:when>
			<xsl:when test="../@type='gaptext'">text</xsl:when>
			<xsl:otherwise><input type="checkbox"/></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

      		<xsl:choose>
			<xsl:when test="../@type='multiplechoice'">
				<br/><input type="{$typeToShow}"/>
			</xsl:when>
			<xsl:when test="../@type='gaptext'">
				<xsl:variable name="length">
						<xsl:value-of select="string-length(@correct)"/>
				</xsl:variable>

				<xsl:if test="../@clue='true'">
					<input type="{$typeToShow}" size="{$length}" maxlength="{$length}"/>
				</xsl:if>
				<xsl:if test="not(../@clue='true')">
					<input type="{$typeToShow}"/>
				</xsl:if>
			</xsl:when>
			<xsl:otherwise><input type="{$typeToShow}"/></xsl:otherwise>
		</xsl:choose>
	<xsl:apply-templates/>


  </xsl:template>
  <xsl:template match="version">
	<xsl:value-of select="document('project.xml')//project/variables/version/@value"/>
  </xsl:template>

<xsl:template match="//news">
    <table>
    <tr>
      <td>
        <h3 style="background-color:#e0e0e0">News:</h3>
      </td>
    </tr>

    <xsl:for-each select="document('project.xml')//item">
    <tr>
    <td>
	<xsl:value-of select="@date"/>
        <xsl:if test="@version">
	  (<xsl:value-of select="@version"/>):
	</xsl:if>
	<xsl:if test="@version|@date">
	  :
	</xsl:if>
    </td><td>

	<h3 style="background-color:#e0e0e0"><xsl:value-of select="@header"/></h3>
	  <xsl:apply-templates/>
    </td>
    </tr>
    </xsl:for-each>
    </table>
  </xsl:template>

   <xsl:template match="inlineexample|inex">
    <span style="background-color:#E0E0E0;font-family:courier,courier new,fixed"><xsl:apply-templates/></span>
  </xsl:template>

  <xsl:template match="printversion">
 <xsl:variable name="nodetree">
 <article>
  <xsl:for-each select="document('project.xml')//file"> <!-- document(document('project.xml')//file/@name)//reference -->
        <xsl:variable name="filename">
         <xsl:call-template name="changeextension">
         <xsl:with-param name="name" select="@name"/>
         </xsl:call-template>
        </xsl:variable>

        <xsl:if test="contains (@name, '.xml')"><!-- only look in xml files for cues -->
	<br style="page-break-before:always"/>


	<xsl:copy-of select="document(@name)//s[not(descendant::printversion)]"/><!-- don't get ourselves in an infinite loop-->

  	</xsl:if>

   </xsl:for-each>
  </article>
  </xsl:variable>
  <xsl:apply-templates select="$nodetree">
   <xsl:with-param name="isPrintVersion" select="true"/>
  </xsl:apply-templates>
  </xsl:template>




</xsl:stylesheet>


