<?xml version='1.0'?>

<!DOCTYPE xsl:stylesheet [<!ENTITY stylesheet SYSTEM "MaxReport.css">]>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output indent="yes"
            method="html"
            doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"
            version="4.0"
            encoding="utf-8"
            media-type="text/html"/>

<xsl:template match="max_report">
   <html>      
      <head>
         <xsl:choose>
            <xsl:when test="@stylesheet='embedded'">
               <style type="text/css"><xsl:text>&stylesheet;</xsl:text></style>
            </xsl:when>
            <xsl:otherwise>
               <link rel="stylesheet" type="text/css">
                  <xsl:attribute name="href"><xsl:value-of select="@stylesheet"/></xsl:attribute>
               </link>
            </xsl:otherwise>
         </xsl:choose>
         
         <title><xsl:value-of select="@title"/></title>
      </head>
      <body>
         <center><h1><a name="top"><xsl:value-of select="@title"/></a></h1></center>
         <xsl:if test="@timeStamp != ''">
            <center><xsl:value-of select="@timeStamp"/></center>
         </xsl:if>
         <xsl:apply-templates/>
      </body>
   </html>
</xsl:template>

<xsl:template match="max_provider_report">
    <table class="sectionHeading" width="100%">
      <tr>
         <th>
           <a>
              <xsl:attribute name="name">
                 <xsl:value-of select="@anchor"/>
              </xsl:attribute>
              <xsl:value-of select="@name"/>
           </a>
         </th>
      </tr>
   </table>
   <xsl:apply-templates/>
   <p><a href="#top"><xsl:value-of select="../@backText"/></a></p>
</xsl:template>

<xsl:template match="max_table">
   <table>
      <xsl:if test="@border='false'">
         <xsl:attribute name="class">noborder</xsl:attribute>
      </xsl:if>
      <xsl:if test="@width!=''">
         <xsl:attribute name="width"><xsl:value-of select="@width"/></xsl:attribute>
      </xsl:if>
      <!-- need select="*" so that position() function does not count whitespace -->
      <!-- perhaps we should strip the xml of carriage returns before applying xsl -->
      <xsl:apply-templates select="*"/>
   </table>
</xsl:template>

<xsl:template match="max_row">   
   <tr>
      <xsl:choose> 
         <xsl:when test="../@alternaterows='true'">
            <xsl:attribute name="class">rowcolor<xsl:value-of select="position() mod 2"/></xsl:attribute>
         </xsl:when>
         <xsl:when test="@shaded='true'">
            <xsl:attribute name="class">rowcolor1</xsl:attribute>
         </xsl:when>
      </xsl:choose>   
      <xsl:apply-templates/>
   </tr>
</xsl:template>

<xsl:template match="max_cell">
   <xsl:variable name="output-element">
      <xsl:choose>
         <xsl:when test="@bold='true'">th</xsl:when>
         <xsl:otherwise>td</xsl:otherwise>
      </xsl:choose>
   </xsl:variable>
   <xsl:element name="{$output-element}">
      <xsl:if test="local-name(.)='max_cell'">
         <!-- we don't want to pick up the bold attribute -->
         <xsl:copy-of select="@align | @colspan | @width"/>
      </xsl:if>
      <xsl:if test="./../../@border='false' or ./../@border='false'" >
         <xsl:attribute name="class">noborder</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
   </xsl:element>
</xsl:template>

<xsl:template match="max_list">
   <xsl:variable name="output-element">
      <xsl:choose>
         <xsl:when test="@format='ordered'">ol</xsl:when>
         <xsl:otherwise>ul</xsl:otherwise>
      </xsl:choose>
   </xsl:variable>
   <xsl:element name="{$output-element}">    
      <xsl:if test="@format='nobullet'" >
         <xsl:attribute name="class">nobullet</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
   </xsl:element>
</xsl:template>

<xsl:template match="max_listitem">
   <li><xsl:apply-templates/></li>
</xsl:template>

<xsl:template match="max_link">
   <a>
      <xsl:attribute name="href">
         <xsl:value-of select="@name"/>
      </xsl:attribute>
      <xsl:if test="@openNewPage='true'">
         <xsl:attribute name="target">_blank</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
   </a>
</xsl:template>

<xsl:template match="max_paragraph">
   <p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="max_image">
   <img>
      <xsl:attribute name="src">
         <xsl:value-of select="."/>
      </xsl:attribute>
      <xsl:attribute name="alt"/>
   </img>
</xsl:template>

<xsl:template match="max_anchor">
   <a>
      <xsl:attribute name="name">
         <xsl:value-of select="@name"/>
      </xsl:attribute>
   </a>
</xsl:template>

<xsl:template match="max_custom">
</xsl:template>

<xsl:template match="max_heading1">
   <h1><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template match="max_heading2">
   <h2><xsl:apply-templates/></h2>
</xsl:template>

<xsl:template match="max_heading3">
   <h3><xsl:apply-templates/></h3>
</xsl:template>

<xsl:template match="max_bold">
   <b><xsl:apply-templates/></b>
</xsl:template>

<xsl:template match="max_italic">
   <i><xsl:apply-templates/></i>
</xsl:template>

<xsl:template match="max_underline">
   <u><xsl:apply-templates/></u>
</xsl:template>

<xsl:template match="max_center">
   <center><xsl:apply-templates/></center>
</xsl:template>

<xsl:template match="max_comment">
   <xsl:comment><xsl:apply-templates/></xsl:comment>
</xsl:template>

<xsl:template match="max_br">
   <br/>
</xsl:template>

</xsl:stylesheet>
