﻿<xsl:transform  version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
				exclude-result-prefixes="xsl xs">
  <xsl:output method="html"/>
  <xsl:template match="rss/channel">
    <xsl:apply-templates select="item">
      <xsl:sort select="title" />
    </xsl:apply-templates >
  </xsl:template>

  <xsl:template match="title">
    <xsl:value-of select="text()"/>
  </xsl:template>

  <xsl:template match="item">
    <table border="1" bordercolor="#000000" cellpadding="1" cellspacing="0" width="100%">
      <tr>
        <td bgColor="#EEEEEE" colspan="2">
          <b>
            <a>
              <xsl:attribute name="name">
                <xsl:value-of select ="title"/>
              </xsl:attribute>
              <xsl:attribute name="href">
                <xsl:call-template name="getWSSDescriptionField">
                  <xsl:with-param name="description" select="description"/>
                  <xsl:with-param name="fieldName" select="'Link'"/>
                </xsl:call-template>
              </xsl:attribute>
              <xsl:value-of select ="title"/>
            </a>
            <xsl:variable name="company">
              <xsl:call-template name="getWSSDescriptionField">
                <xsl:with-param name="description" select="description"/>
                <xsl:with-param name="fieldName" select="'Company'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$company!=''">
              <xsl:text>, </xsl:text>
              <xsl:value-of disable-output-escaping="yes" select="$company"/>
            </xsl:if>
            <xsl:variable name="tagLine">
              <xsl:call-template name="getWSSDescriptionField">
                <xsl:with-param name="description" select="description"/>
                <xsl:with-param name="fieldName" select="'Tagline'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$tagLine!='' and test!='&lt;div&gt;&lt;/div&gt;'">
              <xsl:text>, </xsl:text>
              <xsl:value-of disable-output-escaping="yes" select="$tagLine"/>
            </xsl:if>
          </b>
        </td>
      </tr>
      <tr>
        <td valign="top">
          <b>
            <a>
              <xsl:attribute name="href">
                <xsl:call-template name="getWSSDescriptionField">
                  <xsl:with-param name="description" select="description"/>
                  <xsl:with-param name="fieldName" select="'Link'"/>
                </xsl:call-template>
              </xsl:attribute>
              <img border="0">
                <xsl:attribute name="src">
                  <xsl:call-template name="getWSSDescriptionField">
                    <xsl:with-param name="description" select="description"/>
                    <xsl:with-param name="fieldName" select="'Photo'" />
                  </xsl:call-template>
                </xsl:attribute >
                <xsl:attribute name="alt">
                  <xsl:value-of select="title"/>
                </xsl:attribute>
              </img>
              <br/>
              <xsl:value-of select ="title"/>
            </a>
            <xsl:variable name="company">
              <xsl:call-template name="getWSSDescriptionField">
                <xsl:with-param name="description" select="description"/>
                <xsl:with-param name="fieldName" select="'Company'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$company!=''">
              <xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
              <xsl:value-of disable-output-escaping="yes" select="$company"/>
            </xsl:if>
            <xsl:variable name="tagLine">
              <xsl:call-template name="getWSSDescriptionField">
                <xsl:with-param name="description" select="description"/>
                <xsl:with-param name="fieldName" select="'Tagline'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:if test="$tagLine!=''">
              <xsl:text disable-output-escaping="yes">&lt;br/&gt;</xsl:text>
              <xsl:value-of disable-output-escaping="yes" select="$tagLine"/>
            </xsl:if>
            <br/>
            <br/>
            <a>
              <xsl:attribute name="href">
                <xsl:text>Sessions.aspx#</xsl:text>
                <xsl:value-of select ="title"/>
              </xsl:attribute>
              (Sessions)
            </a>
          </b>
        </td>
        <td valign="top" width="80%">
          <b>
            <xsl:variable name="bio">
              <xsl:call-template name="getWSSDescriptionField">
                <xsl:with-param name="description" select="description"/>
                <xsl:with-param name="fieldName" select="'Bio'"/>
              </xsl:call-template>
            </xsl:variable>
            <xsl:value-of disable-output-escaping="yes" select ="$bio"/>
          </b>
        </td>
      </tr>
    </table>
    <br/>
  </xsl:template>

  <xsl:template name="getWSSDescriptionField">
    <xsl:param name="description"/>
    <xsl:param name="fieldName"/>

    <xsl:variable name="before" select="concat($fieldName,':&lt;/b&gt; ')" />
    <xsl:variable name="after" select ="'&lt;/div&gt;'" />
    <xsl:variable name="htmlFieldStart" select ="'&lt;div class=ExternalClass'" />

    <xsl:variable name = "leftRemoved" >
      <xsl:value-of select="substring-after($description,$before)"/>
    </xsl:variable>
    <xsl:variable name = "results">
      <xsl:value-of disable-output-escaping="yes" select = "substring-before($leftRemoved,$after)" />
    </xsl:variable>

    <!-- HTML fields have extra <div>-->
    <xsl:choose>
      <xsl:when test="starts-with($results, $htmlFieldStart)">
        <xsl:value-of select = "substring-after($results,'&gt;')" />
      </xsl:when >
      <xsl:otherwise>
        <xsl:value-of select ="$results"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:transform>
