<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="no" omit-xml-declaration="yes" encoding="UTF-8"/> 

<xsl:template match="@*|*">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="preform">
<xsl:value-of disable-output-escaping="yes" select="."/>
</xsl:template>

<xsl:template match="NEWLINE|newline">
<xsl:element name="br">
</xsl:element>
</xsl:template>

<xsl:template match="LINK">
<xsl:element name="a">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>


<xsl:template match="image">
<div>
	<xsl:attribute name="class">
    	<xsl:value-of select="@align"/>
    </xsl:attribute>
	<div>
      <xsl:attribute name="class">image</xsl:attribute>
       <img>
        <xsl:attribute name="src">
        <xsl:value-of select="@src"/>
        </xsl:attribute>
        <xsl:attribute name="alt">
        <xsl:value-of select="@alttext"/>
        </xsl:attribute>
        <xsl:attribute name="width">
        <xsl:value-of select="@width"/>
        </xsl:attribute>
        <xsl:attribute name="height">
        <xsl:value-of select="@height"/>
        </xsl:attribute>
        <xsl:attribute name="border">0</xsl:attribute>
      </img>
      <div class="imageCaption">
      <xsl:attribute name="style">width: <xsl:value-of select="@width" />px;</xsl:attribute>
      <xsl:value-of select="@caption"/>
      </div>
    </div>
</div>
</xsl:template>

<xsl:template match="MEDIA">
<reference>
<xsl:attribute name="type">media</xsl:attribute>
<xsl:attribute name="dbid">
<xsl:value-of select="@dbid"/>
</xsl:attribute>
<xsl:attribute name="caption">
<xsl:value-of select="@caption"/>
</xsl:attribute>
</reference>
</xsl:template>

<xsl:template match="table">
<table>
  <xsl:attribute name="class">default</xsl:attribute>
  <xsl:attribute name="border">0</xsl:attribute>
  <xsl:attribute name="width">100%</xsl:attribute>
  
  <xsl:for-each select="tr">
    <tr>
      <xsl:attribute name="class">
        <xsl:choose>
          <xsl:when test="position() mod 2 = 1">
            <xsl:text>defaultShade1</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>defaultShade2</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:apply-templates />
    </tr>
  </xsl:for-each>
</table>
</xsl:template>

<xsl:template match="th">
  <th>
    <xsl:attribute name="class">default</xsl:attribute>
    <xsl:attribute name="bgcolor">#333333</xsl:attribute>
    <xsl:apply-templates select="@*" />
    <xsl:apply-templates />
  </th>
</xsl:template>

<xsl:template match="table/tr/td/p">
  <p class="sectionLeadText">
    <xsl:apply-templates />
  </p>
</xsl:template>

<xsl:template match="table/tr/th/p">
  <p class="sectionLeadText">
    <xsl:apply-templates />
  </p>
</xsl:template>

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

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


</xsl:stylesheet>

