<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
  doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" 
  encoding="ISO-8859-1"/>

<xsl:template match="/">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
      <title>Lernen mit MILCA</title>
      <!-- Das Script-Zeug brauchts fuer den Multiple Choice Test -->
      <script language="JavaScript"> 
        function Correct(){alert("Correct!")} 
        function Incorrect(){ alert("Incorrect!")}
      </script>
    </head> 
    <body color="#000000"> 
      <hr/>
      <ul>
        <xsl:apply-templates select="chapter" mode="inhaltsverzeichnis"/>
      </ul>
      <hr/>
      <xsl:apply-templates select="chapter" mode="inhalt"/>
    </body>
  </html>
</xsl:template>

<!-- Abbildung unserer Hierarchie auf die HTML-Tags h1 bis h6 -->
<xsl:template match="chapter" mode="inhalt">
  <h1><xsl:value-of select="title"/></h1> 
  <xsl:apply-templates select="section"/>
</xsl:template>

<xsl:template match="section">
  <h2><xsl:value-of select="sectiontitle"/></h2>
    <xsl:apply-templates select="p|ol|ul|exer|examp|a|blockquote|cap|div|lkdemo|mct|table|subsection"/>
</xsl:template>

<xsl:template match="subsection">
  <h3><xsl:value-of select="subsectiontitle"/></h3>
    <xsl:apply-templates select="p|ol|ul|exer|examp|a|blockquote|cap|div|lkdemo|mct|table|subsubsection"/>
</xsl:template>

<xsl:template match="subsubsection">
  <h4><xsl:value-of select="subsubsectiontitle"/></h4>
    <xsl:apply-templates select="p|ol|ul|exer|examp|a|blockquote|cap|div|lkdemo|mct|table|subsubsubsection"/>
</xsl:template>

<xsl:template match="subsubsubsection">
  <h5><xsl:value-of select="subsubsubsectiontitle"/></h5>
    <xsl:apply-templates select="p|ol|ul|exer|examp|a|blockquote|cap|div|lkdemo|mct|table|subsubsubsubsection"/>
</xsl:template>

<xsl:template match="subsubsubsubsection">
  <h6><xsl:value-of select="subsubsubsubsectiontitle"/></h6>
    <xsl:apply-templates select="p|ol|ul|exer|examp|a|blockquote|cap|div|lkdemo|mct|table"/>
</xsl:template>

<xsl:template match="ul|ol">
<!-- so erreicht man einen shallow copy inklusive Attribute -->
<!-- copy alleine wuerde die Attribute auslassen -->
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="li"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="lkdemo">
  <xsl:apply-templates select="a"/>
</xsl:template>

<xsl:template match="mct">
  <hr/><font size="22" color="red">Multiple Choice Test</font><hr/>
    <xsl:apply-templates select="mct_question"/>
  <hr/>
</xsl:template>
<xsl:template match="mct_question">
  <form>
    <xsl:apply-templates select="mct_intro|choice"/>
  </form><hr/>
</xsl:template>

<xsl:template match="mct_intro">
  <p><font size="22" color="blue"><xsl:value-of select="text()"/></font></p>
</xsl:template>
<xsl:template match="choice">
  <xsl:variable name="null">0</xsl:variable>
  <xsl:variable name="eins">1</xsl:variable>
  <xsl:if test="@answer=$null">
    <input type="radio" onclick="Incorrect()"/><xsl:value-of select="text()"/><br/>
  </xsl:if>
  <xsl:if test="@answer=$eins">
    <input type="radio" onclick="Correct()"/><xsl:value-of select="text()"/><br/>
  </xsl:if>
</xsl:template>


<xsl:template match="img">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
  </xsl:copy>
  <!-- Nur wenn es eine Bildunterschrift gibt, wird sie auch angelegt -->
  <xsl:if test="cap">
    <p><font color="red"><xsl:value-of select="cap"/></font></p>
  </xsl:if>
</xsl:template>

<xsl:template match="table">
  <xsl:if test="cap">
    <caption><font color="red"><xsl:value-of select="capture"/></font></caption>
  </xsl:if>
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="tr"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="tr">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="td"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="biblio|blockquote|cite|em|i|pre|b|font">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:value-of select="text()"/>
  </xsl:copy>
</xsl:template>

<!-- alles mit Labeling wird ausgefiltert -->
<xsl:template match="a">
  <xsl:if test="not(@name)">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:value-of select="text()"/>
    </xsl:copy>
  </xsl:if>
</xsl:template>

<xsl:template match="capture|div|examp|exer|gloss|li|p|td">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates select="*|text()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="text()">
  <font size="22"><xsl:value-of select="."/></font>
</xsl:template>

<!-- Erzeugen eines simplen Inhaltsverzeichnisses bis in dritte Tiefe -->
<xsl:template match="chapter|section|subsection" mode="inhaltsverzeichnis">
    <li>
      <font size="22" color="green"><xsl:value-of select="title|sectiontitle|subsectiontitle"/></font> 
      <xsl:apply-templates select="section|subsection" mode="inhaltsverzeichnis"/>
    </li>
</xsl:template>

</xsl:stylesheet>
