﻿<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:key name="sponsorLevel" match="*[@sponsorLevel]" use="@sponsorLevel" />

	<xsl:template match="rss/channel">
		<xsl:for-each select="item">
			<xsl:sort select="substring-before(substring-after(description, 'SponsorshipLevel:&lt;/b&gt;'), '&lt;/div&gt;')" />
			<xsl:sort select="title" />
			<xsl:variable name = "sponsorLevelChange" select="''" />
			<xsl:variable name = "sponsorLevel">
				<xsl:call-template name="getWSSDescriptionField">
					<xsl:with-param name="description" select="description"/>
					<xsl:with-param name="fieldName" select="'SponsorshipLevel'"/>
				</xsl:call-template>
			</xsl:variable >
			<xsl:apply-templates
	select="*[@sponsorLevel and
                generate-id(.)=generate-id(key('sponsorLevel', @sponsorLevel))]" />
			<a target="_blank">
				<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="'Logo'"/>
						</xsl:call-template>
					</xsl:attribute >
					<xsl:attribute name="alt">
						<xsl:value-of select="title"/>
					</xsl:attribute>
				</img>
			</a>
			<br/>
			<br/>
			<br/>
			<!--
		<xsl:value-of disable-output-escaping="yes" select="description"/>
		-->
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="*[@sponsorLevel]">
		<xsl:value-of select="@sponsorLevel" />
			</xsl:template>


	<xsl:template match="title">
		<xsl:value-of select="text()"/>
	</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>
