<?xml version="1.0" encoding="UTF-8"?>
<!--
Style sheet for displaying login information

This stylesheet transforms XML data on the
form:
  <login>
    [errors]
    <user>someName</user>
  </login>

If the user-element has no content, a login GUI
with a username and password field is displayed.
If the element has a username as content, the username
and a logout button is displayed.

Author: Hans S. Toemmerholt, INF5270 V05

See also:
login.php
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" version="4.01" encoding="UTF-8" indent="yes"
      doctype-public="-//W3C//DTD HTML 4.01//EN" 
      doctype-system="http://www.w3c.org/TR/html4/strict.dtd"/>

  <xsl:include href="error.xsl"/>

  <!--
  Match the top level element <login/>
  -->
  <xsl:template match="login">
    <xsl:for-each select="*">
      <xsl:apply-templates select="."/>
    </xsl:for-each>
  </xsl:template>

  <!--
  Match the <user/> element
  -->
  <xsl:template match="user">
    <div id="login">
    <xsl:choose>
      <!-- Does the current node (.) have text content? -->
      <xsl:when test=" . = '' ">
        <!-- Display login GUI -->
        <form method="post" action="login.php">
          <p>
            <label for="userField">Username:</label>
            <input id="userField" type="text" name="userName"/><br/>
            <label for="passField">Password</label>
            <input id="passField" type="password" name="password"/><br/>
            <input type="submit" value="Login"/>
          </p>
        </form>
      </xsl:when>
      <xsl:otherwise>
        <!-- Display login information -->
        <form method="post" action="logout.php">
          <p>You are logged in as <xsl:value-of select="."/></p>
          <p><input type="submit" value="logout"/></p>
        </form>
      </xsl:otherwise>
    </xsl:choose>
    </div>
  </xsl:template>

</xsl:stylesheet>

