<?xml version="1.0" encoding="UTF-8" ?>
<!--
Style sheet for displaying comments.

This style sheet displays a list of comments
and a GUI for login. If the user is logged in
it also displays a GUI for adding comments.

Author: Hans S. Toemmerholt, INF5270
-->
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:c="http://www.ifi.uio.no/inf5270"
    exclude-result-prefixes="c">
    <!-- Note -->

  <xsl:output method="html" version="4.01" encoding="UTF-8"
      doctype-public="-//W3C//DTD HTML 4.01//EN"
      doctype-system="http://www.w3.org/TR/html4/DTD/strict.dtd"/>
    
  <xsl:include href="login.xsl"/>
  <xsl:include href="error.xsl"/>
  
  <!--
  Template for the comments element.
  -->  
  <xsl:template match="comments">
<html>
  <head>
    <title>Comments for <xsl:value-of select="@nodeid"/></title>
    <link rel="stylesheet" type="text/css" href="comment.css"/>
  </head>

  <body>

    <h1>Comments for <xsl:value-of select="@nodeid"/></h1>

    <!-- Display login status and GUI -->
    <xsl:apply-templates select="document('login.php')/login"/>

    <!-- Must be logged in to post comments -->
    <xsl:if test=" document('login.php')/login/user != '' ">
      <xsl:call-template name="commentGUI"/>
    </xsl:if>
    
    <!-- Process comments and errors -->
    <xsl:for-each select="*">
      <xsl:apply-templates select="."/>
    </xsl:for-each>

  </body>

</html>
  </xsl:template>

  <!--
  Format comments
  -->
  <xsl:template match="comment">
    <div class="comment">
      <div class="commHead">
        <p class="commSub"><xsl:value-of select="comment/c:text/c:subject"/></p>
        <p class="commInfo">
          by <xsl:value-of select="@usrname"/>
          @<xsl:value-of select="@registered"/>
        </p>
      </div>
      <div class="commBody">
        <xsl:for-each select="comment/c:text/c:p">
          <p><xsl:value-of select="."/></p>
        </xsl:for-each>
      </div>
    </div>
  </xsl:template>

  <!--
  Create an interface for adding comments.
  -->
  <xsl:template name="commentGUI">
    <form id="commentForm" method="get" action="comment.php">
      <p>
        <input type="hidden" name="nodeid" value="{@nodeid}"/>
        <label for="subField">Enter a subject:</label><br/>
        <input id="subField" type="text" name="subject"/>
      </p>
      <p>
        <label for="commArea">Enter your comment:</label><br/>
        <textarea id="commArea" name="comment" cols="30" rows="10"></textarea>
      </p>
      <p><input type="submit" value="Post your comment"/></p>
    </form>
  </xsl:template>

</xsl:stylesheet>

  

