﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
	<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

	<xsl:template match="/">
		<xsl:for-each select="/AjaxRequest/DynamicCss/Class">
			<xsl:choose>
				<xsl:when test="@name">
					<xsl:text>.</xsl:text>
					<xsl:value-of select="@name"/>
					<xsl:text>{</xsl:text>
					<xsl:for-each select="./Style">
						<xsl:value-of select="."/>	
					</xsl:for-each>
					<xsl:text>}</xsl:text>
				</xsl:when>				
			</xsl:choose>
		</xsl:for-each>

		<xsl:for-each select="/AjaxRequest/DynamicCss/Legacy/Control">
			<xsl:choose>
				<xsl:when test="@class">
					<xsl:text>.</xsl:text>
					<xsl:value-of select="@class"/>
					<xsl:text>{</xsl:text>
					<xsl:for-each select="./Attribute">
						<xsl:value-of select="@name"/>
						<xsl:text>:</xsl:text>
						<xsl:value-of select="Value"/>
						<xsl:text> !important;</xsl:text>
					</xsl:for-each>
					<xsl:text>}</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@type"/>
					<xsl:text>{</xsl:text>
					<xsl:for-each select="./Attribute">
						<xsl:variable name="AttributeName" select="@name"></xsl:variable>
						<xsl:value-of select="@name"/>
						<xsl:text>:</xsl:text>
						<xsl:value-of select="Value"/>
						<xsl:text> !important;</xsl:text>
						<xsl:if test="Attribute[@effect = 'gradient']">
							<xsl:variable name="StartColorRGB" select="Attribute/StartColorRGB"></xsl:variable>
							<xsl:variable name="EndColorRGB" select="Attribute/EndColorRGB"></xsl:variable>
							<xsl:variable name="StartColorHex" select="Attribute/StartHexColor"></xsl:variable>
							<xsl:variable name="EndColorHex" select="Attribute/EndHexColor"></xsl:variable>

							<xsl:value-of select="$AttributeName"/>
							<xsl:text>:-moz-linear-gradient(top,</xsl:text>
							<xsl:value-of select="$StartColorRGB"></xsl:value-of>
							<xsl:text>,0%,</xsl:text>
							<xsl:value-of select="$EndColorRGB"></xsl:value-of>
							<xsl:text> 100%);</xsl:text>

							<xsl:value-of select="$AttributeName"/>
							<xsl:text>:-webkit-gradient(linear, left top, left bottom, color-stop(0%,</xsl:text>
							<xsl:value-of select="$StartColorRGB"></xsl:value-of>
							<xsl:text>)),color-stop(100%,</xsl:text>
							<xsl:value-of select="$EndColorRGB"></xsl:value-of>
							<xsl:text>));</xsl:text>

							<xsl:value-of select="$AttributeName"/>
							<xsl:text>:-webkit-linear-gradient(top,</xsl:text>
							<xsl:value-of select="$StartColorRGB"></xsl:value-of>
							<xsl:text>,0%,</xsl:text>
							<xsl:value-of select="$EndColorRGB"></xsl:value-of>
							<xsl:text> 100%);</xsl:text>

							<xsl:value-of select="$AttributeName"/>
							<xsl:text>:-o-linear-gradient(top,</xsl:text>
							<xsl:value-of select="$StartColorRGB"></xsl:value-of>
							<xsl:text> 0%,</xsl:text>
							<xsl:value-of select="$EndColorRGB"></xsl:value-of>
							<xsl:text> 100%);</xsl:text>


							<xsl:value-of select="$AttributeName"/>
							<xsl:text>:-ms-linear-gradient(top,</xsl:text>
							<xsl:value-of select="$StartColorRGB"></xsl:value-of>
							<xsl:text> 0%,</xsl:text>
							<xsl:value-of select="$EndColorRGB"></xsl:value-of>
							<xsl:text> 100%);</xsl:text>

							<xsl:value-of select="$AttributeName"/>
							<xsl:text>:linear-gradient(to bottom,</xsl:text>
							<xsl:value-of select="$StartColorRGB"></xsl:value-of>
							<xsl:text> 0%,</xsl:text>
							<xsl:value-of select="$EndColorRGB"></xsl:value-of>
							<xsl:text> 100%);</xsl:text>


							<xsl:text>filter</xsl:text>
							<xsl:text>:progid:DXImageTransform.Microsoft.gradient(startColorstr=</xsl:text>
							<xsl:value-of select="$StartColorHex"></xsl:value-of>
							<xsl:text>,endColorstr=</xsl:text>
							<xsl:value-of select="$EndColorHex"></xsl:value-of>
							<xsl:text>,GradientType=0);</xsl:text>

						</xsl:if>
					</xsl:for-each>
					<xsl:text>}</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>

		<xsl:for-each select="/AjaxRequest/DynamicCss/Control">
			<xsl:choose>
				<xsl:when test="@class">
					<xsl:text>.</xsl:text>
					<xsl:value-of select="@class"/>
					<xsl:text>{</xsl:text>
					<xsl:for-each select="./Attribute">
						<xsl:value-of select="@name"/>
						<xsl:text>:</xsl:text>
						<xsl:value-of select="Value"/>
						<xsl:text> !important;</xsl:text>
					</xsl:for-each>
					<xsl:text>}</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="@type"/>
					<xsl:text>{</xsl:text>
					<xsl:for-each select="./Attribute">
						<xsl:variable name="AttributeName" select="@name"></xsl:variable>
						<xsl:value-of select="@name"/>
						<xsl:text>:</xsl:text>
						<xsl:value-of select="Value"/>
						<xsl:text> !important;</xsl:text>						
					</xsl:for-each>
					<xsl:text>}</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
