<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:CxF="http://colorexchangeformat.com/v2"
	xmlns:cc="http://colorexchangeformat.com/CxF3-core">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
<xsl:template match="/">
  <html>
  <body>
  <h3>CxF Generic Viewer Stylesheet</h3>
 	<xsl:apply-templates select="CxF:CxF/CxF:Preamble"/>
 	<xsl:apply-templates select="//SampleSet"/>
	<xsl:apply-templates select="cc:CxF/cc:FileInformation"/>
	<xsl:apply-templates select="cc:CxF/cc:CustomResources"/>
	<xsl:apply-templates select="cc:CxF/cc:Resources"/>
  </body>
  </html>
</xsl:template>
<xsl:template match="SampleSet">
<h4 style="text-decoration : underline ; color: white; background: red;">Note: This file is a CXF1 format!</h4>
<h5>It contains the following Samples in the SampleSet: <xsl:value-of select="./Name"/></h5>
<ol>
	<xsl:for-each select="./Sample">
	<li><xsl:value-of select="./Name"/></li>
	</xsl:for-each>
</ol>
</xsl:template>
<xsl:template match="CxF:Preamble">
<h4 style="text-decoration : underline ; color: black; background: yellow;">Note: This file is a CXF2 format!</h4>
<h5>Created by: <xsl:value-of select="CxF:Header/CxF:Creator"/></h5>
<xsl:variable name="CXF2Palette_ext" select="//CxF:CxF/CxF:Palette[1]"/>
<xsl:if test="$CXF2Palette_ext">
<h5>It contains the following Palettes/ColorSets/Colors:</h5>
	<xsl:for-each select="//CxF:CxF/CxF:Palette">
		<xsl:for-each select="CxF:ColorSet">
		<h5>Palette=<xsl:value-of select="../@PaletteName"/>  - ( ColorSet=<xsl:value-of select="@ColorSetName"/> )</h5>
  <table border="1">
      <tr bgcolor="#b4b4b4">
        <th align="center"> </th>
        <th align="center"> </th>
	<th colspan="3" align="center">sRGB</th>
	<th colspan="3" align="center">CIE L*a*b*</th>
	<th colspan="4" align="center">CMYK</th>
	<th align="center" cellpadding="3" >Spectral</th>
      </tr>
      <tr bgcolor="#b4b4b4">
        <th align="center">No.</th>
        <th align="center" cellpadding="3" >Name</th>
	<th align="center" cellpadding="3" >R</th>
	<th align="center" cellpadding="3" >G</th>
	<th align="center" cellpadding="3" >B</th>
	<th align="center" cellpadding="3" >L*</th>
	<th align="center" cellpadding="3" >a*</th>
	<th align="center" cellpadding="3" >b*</th>
	<th align="center" cellpadding="3" >C</th>
	<th align="center" cellpadding="3" >M</th>
	<th align="center" cellpadding="3" >Y</th>
	<th align="center" cellpadding="3" >K</th>
	<th align="center" cellpadding="3" >Values</th>
      </tr>
			<xsl:for-each select="CxF:Color">
			<tr>
				<td><xsl:number format="1"/></td>
                <td style="white-space: nowrap;"><xsl:value-of select="@ColorName"/></td>
				  <xsl:variable name="CXF2Spectral_ext" select="CxF:ColorSpaceSpectral"/>
				  <xsl:variable name="CXF2CIELab_ext" select="CxF:ColorSpaceCIELab"/>
				  <xsl:variable name="CXF2SRGB_ext" select="CxF:ColorSpaceSRGB"/>
				  <xsl:variable name="CXF2CMYK_ext" select="CxF:ColorSpaceCMYK"/>
				<xsl:if test="$CXF2SRGB_ext"> 
				  <xsl:variable name="CXF2SRGB_R" select="CxF:ColorSpaceSRGB/CxF:Red"/>
				  <xsl:variable name="CXF2SRGB_G" select="CxF:ColorSpaceSRGB/CxF:Green"/>
				  <xsl:variable name="CXF2SRGB_B" select="CxF:ColorSpaceSRGB/CxF:Blue"/>
						       <td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF2SRGB_R,"###")'/></td>
						       <td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF2SRGB_G,"###")'/></td>
						       <td><xsl:value-of select='format-number($CXF2SRGB_B,"###")'/></td>
						       </xsl:if>
			   <xsl:if test="not($CXF2SRGB_ext)">
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>						   
				</xsl:if>
				<xsl:if test="$CXF2CIELab_ext"> 
				  <xsl:variable name="CXF2CIELab_L" select="CxF:ColorSpaceCIELab/CxF:L"/>
				  <xsl:variable name="CXF2CIELab_A" select="CxF:ColorSpaceCIELab/CxF:A"/>
				  <xsl:variable name="CXF2CIELab_B" select="CxF:ColorSpaceCIELab/CxF:B"/>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF2CIELab_L,"##0.00")'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF2CIELab_A,"##0.00")'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF2CIELab_B,"##0.00")'/></td>
						       </xsl:if>
			   <xsl:if test="not($CXF2CIELab_ext)">
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>						   
				</xsl:if>
				<xsl:if test="$CXF2CMYK_ext"> 
				  <xsl:variable name="CXF2CMYK_C" select="CxF:ColorSpaceCMYK/CxF:Cyan"/>
				  <xsl:variable name="CXF2CMYK_M" select="CxF:ColorSpaceCMYK/CxF:Magenta"/>
				  <xsl:variable name="CXF2CMYK_Y" select="CxF:ColorSpaceCMYK/CxF:Yellow"/>
				  <xsl:variable name="CXF2CMYK_K" select="CxF:ColorSpaceCMYK/CxF:Black"/>
						<td style="white-space: nowrap;"><xsl:value-of select='CXF2CMYK_C'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='CXF2CMYK_M'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='CXF2CMYK_Y'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='CXF2CMYK_K'/></td>
						       </xsl:if>
			   <xsl:if test="not($CXF2CMYK_ext)">
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>						   
				</xsl:if>
				<xsl:if test="$CXF2Spectral_ext"> 
						    <td style="white-space: nowrap;"><xsl:for-each select="CxF:ColorSpaceSpectral/CxF:ReflectancePoint">
								<xsl:variable name="rvalue" select="."/>
								<xsl:value-of select='format-number($rvalue," 0.0000")'/> 
						    </xsl:for-each></td>
				</xsl:if>
			   <xsl:if test="not($CXF2Spectral_ext)">
						    <td>[No Spectral values]</td>
				</xsl:if>
			</tr> 
			</xsl:for-each>
			</table>
		</xsl:for-each>
	</xsl:for-each>
	</xsl:if>
	<xsl:if test="not($CXF2Palette_ext)">
<h5>It contains the following ColorQualityControl/Colors:</h5>
	<xsl:for-each select="//CxF:CxF/CxF:ColorQualityControl">
		<xsl:for-each select="CxF:StandardAndMeasurement">
		<h5>Standard =<xsl:value-of select="./CxF:Standard/CxF:Color/@ColorName"/></h5>
 <table border="1">
      <tr bgcolor="#b4b4b4">
        <th align="center"> </th>
        <th align="center"> </th>
	<th colspan="3" align="center">sRGB</th>
	<th colspan="3" align="center">CIE L*a*b*</th>
	<th colspan="4" align="center">CMYK</th>
	<th align="center" cellpadding="3" >Spectral</th>
      </tr>
      <tr bgcolor="#b4b4b4">
        <th align="center">No.</th>
        <th align="center" cellpadding="3" >Name</th>
	<th align="center" cellpadding="3" >R</th>
	<th align="center" cellpadding="3" >G</th>
	<th align="center" cellpadding="3" >B</th>
	<th align="center" cellpadding="3" >L*</th>
	<th align="center" cellpadding="3" >a*</th>
	<th align="center" cellpadding="3" >b*</th>
	<th align="center" cellpadding="3" >C</th>
	<th align="center" cellpadding="3" >M</th>
	<th align="center" cellpadding="3" >Y</th>
	<th align="center" cellpadding="3" >K</th>
	<th align="center" cellpadding="3" >Values</th>
      </tr>
			<xsl:for-each select="CxF:Measurement">
			<tr>
				<td><xsl:number format="1"/></td>
                <td style="white-space: nowrap;"><xsl:value-of select="CxF:Color/@ColorName"/></td>
				  <xsl:variable name="CXF2Spectral_ext" select="CxF:Color/CxF:ColorSpaceSpectral"/>
				  <xsl:variable name="CXF2CIELab_ext" select="CxF:Color/CxF:ColorSpaceCIELab"/>
				  <xsl:variable name="CXF2SRGB_ext" select="CxF:Color/CxF:ColorSpaceSRGB"/>
				  <xsl:variable name="CXF2CMYK_ext" select="CxF:Color/CxF:ColorSpaceCMYK"/>
				<xsl:if test="$CXF2SRGB_ext"> 
				  <xsl:variable name="CXF2SRGB_R" select="CxF:Color/CxF:ColorSpaceSRGB/CxF:Red"/>
				  <xsl:variable name="CXF2SRGB_G" select="CxF:Color/CxF:ColorSpaceSRGB/CxF:Green"/>
				  <xsl:variable name="CXF2SRGB_B" select="CxF:Color/CxF:ColorSpaceSRGB/CxF:Blue"/>
						       <td><xsl:value-of select='format-number($CXF2SRGB_R,"###")'/></td>
						       <td><xsl:value-of select='format-number($CXF2SRGB_G,"###")'/></td>
						       <td><xsl:value-of select='format-number($CXF2SRGB_B,"###")'/></td>
						       </xsl:if>
			   <xsl:if test="not($CXF2SRGB_ext)">
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>						   
				</xsl:if>
				<xsl:if test="$CXF2CIELab_ext"> 
				  <xsl:variable name="CXF2CIELab_L" select="CxF:Color/CxF:ColorSpaceCIELab/CxF:L"/>
				  <xsl:variable name="CXF2CIELab_A" select="CxF:Color/CxF:ColorSpaceCIELab/CxF:A"/>
				  <xsl:variable name="CXF2CIELab_B" select="CxF:Color/CxF:ColorSpaceCIELab/CxF:B"/>
						<td><xsl:value-of select='format-number($CXF2CIELab_L,"###.00")'/></td>
						<td><xsl:value-of select='format-number($CXF2CIELab_A,"###.00")'/></td>
						<td><xsl:value-of select='format-number($CXF2CIELab_B,"###.00")'/></td>
						       </xsl:if>
			   <xsl:if test="not($CXF2CIELab_ext)">
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>						   
				</xsl:if>
				<xsl:if test="$CXF2CMYK_ext"> 
				  <xsl:variable name="CXF2CMYK_C" select="CxF:Color/CxF:ColorSpaceCMYK/CxF:Cyan"/>
				  <xsl:variable name="CXF2CMYK_M" select="CxF:Color/CxF:ColorSpaceCMYK/CxF:Magenta"/>
				  <xsl:variable name="CXF2CMYK_Y" select="CxF:Color/CxF:ColorSpaceCMYK/CxF:Yellow"/>
				  <xsl:variable name="CXF2CMYK_K" select="CxF:Color/CxF:ColorSpaceCMYK/CxF:Black"/>
						<td><xsl:value-of select='CXF2CMYK_C'/></td>
						<td><xsl:value-of select='CXF2CMYK_M'/></td>
						<td><xsl:value-of select='CXF2CMYK_Y'/></td>
						<td><xsl:value-of select='CXF2CMYK_K'/></td>
						       </xsl:if>
			   <xsl:if test="not($CXF2CMYK_ext)">
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>
					   <td>n/a</td>						   
				</xsl:if>
				<xsl:if test="$CXF2Spectral_ext"> 
						    <td>[Has Spectral values]</td>
				</xsl:if>
			   <xsl:if test="not($CXF2Spectral_ext)">
						    <td>[No Spectral values]</td>
				</xsl:if>
			</tr> 
			</xsl:for-each>
			</table>
		</xsl:for-each>
	</xsl:for-each>
	</xsl:if>
</xsl:template>
<xsl:template match="cc:CustomResources">
<h5 style="text-decoration : underline;">Note: This file contains the following Custom Resources:</h5>
	<xsl:for-each select="node()">
		<h5>namespace=<xsl:value-of select="namespace-uri(.)"/></h5>
	</xsl:for-each>
</xsl:template>
<xsl:template match="cc:FileInformation">
<h5 style="text-decoration : underline;">File Information Header</h5>
<h5>Creator=<xsl:value-of select="cc:Creator"/></h5>
<h5>Description=<xsl:value-of select="cc:Description"/></h5>
	<xsl:for-each select="cc:Tag">
		<h6><xsl:value-of select="@Name"/> = <xsl:value-of select="@Value"/></h6>
	</xsl:for-each>
</xsl:template>
<xsl:template match="cc:Resources/cc:ObjectCollection">
 <h4 style="text-decoration : underline ; color: white; background: blue;">Note: This file is a CXF3 format!</h4>
  <table border="1">
      <tr bgcolor="#b4b4b4">
        <th align="center"> </th>
        <th align="center"> </th>
        <th align="center"> </th>
        <th align="center"> </th>
	<th align="center">HTML</th>
	<th colspan="3" align="center">sRGB</th>
	<th colspan="3" align="center">CIE L*a*b*</th>
	<th colspan="3" align="center">CIE XYZ</th>
	<th colspan="4" align="center">CMYK</th>
	<th align="center" cellpadding="3" >Spectral</th>
      </tr>
      <tr bgcolor="#b4b4b4">
        <th align="center">No.</th>
        <th align="center" cellpadding="3" >ID</th>
        <th align="center" cellpadding="3" >Name</th>
        <th align="center" cellpadding="3" >Type</th>
	<th align="center" cellpadding="3" >patch</th>
	<th align="center" cellpadding="3" >R</th>
	<th align="center" cellpadding="3" >G</th>
	<th align="center" cellpadding="3" >B</th>
	<th align="center" cellpadding="3" >L*</th>
	<th align="center" cellpadding="3" >a*</th>
	<th align="center" cellpadding="3" >b*</th>
	<th align="center" cellpadding="3" >X</th>
	<th align="center" cellpadding="3" >Y</th>
	<th align="center" cellpadding="3" >Z</th>
	<th align="center" cellpadding="3" >C</th>
	<th align="center" cellpadding="3" >M</th>
	<th align="center" cellpadding="3" >Y</th>
	<th align="center" cellpadding="3" >K</th>
	<th align="center" cellpadding="3" >Values</th>
      </tr>
      <xsl:for-each select="cc:Object">
	<tr>
            <td><xsl:number format="1"/></td>
             <td style="white-space: nowrap;"><xsl:value-of select="@Id"/></td>
           <td style="white-space: nowrap;"><xsl:value-of select="@Name"/></td>
            <td style="white-space: nowrap;"><xsl:value-of select="@ObjectType"/></td>
		    <xsl:variable name="DeviceColorValues_ext" select="cc:DeviceColorValues"/>
		    <xsl:variable name="HTML_ext" select="cc:DeviceColorValues/cc:ColorHTML[1]"/>
			<xsl:if test="not($HTML_ext)">
				<td>n/a</td>
			</xsl:if>			   		   		    
	    <xsl:if test="$DeviceColorValues_ext"> 
		     <xsl:for-each select="cc:DeviceColorValues">
		         <xsl:if test="$HTML_ext"> 
					<xsl:for-each select="cc:ColorHTML[1]/@HTML">
						<td bgcolor="{.}"> </td>
					</xsl:for-each>
				</xsl:if>
		    </xsl:for-each>
		    </xsl:if>
			<xsl:for-each select="cc:ColorValues">
		      <xsl:variable name="SRGB_ext" select="cc:ColorSRGB"/>
		      <xsl:variable name="LAB_ext" select="cc:ColorCIELab"/>
		      <xsl:variable name="XYZ_ext" select="cc:ColorCIEXYZ"/>
		         <xsl:if test="$SRGB_ext"> 
					<xsl:for-each select="cc:ColorSRGB[1]">
					<xsl:variable name="RED" select="./cc:R"/>
					<xsl:variable name="GREEN" select="./cc:G"/>
					<xsl:variable name="BLUE" select="./cc:B"/>
					<xsl:variable name="RGBSUM" select="$RED + $GREEN + $BLUE"/>
					<xsl:variable name="HTMLCode">
							<xsl:call-template name="RGBtoHEX">
								<xsl:with-param name="dRed" select="$RED"/>
								<xsl:with-param name="dGreen" select="$GREEN"/>
								<xsl:with-param name="dBlue" select="$BLUE"/>
					</xsl:call-template>
					</xsl:variable>
					<xsl:choose>
						<xsl:when test="$RGBSUM &lt; 300">
							<td style="color : white;" bgcolor="{$HTMLCode}"><xsl:value-of select="./cc:R"/></td>							
							<td style="color : white;" bgcolor="{$HTMLCode}"><xsl:value-of select="./cc:G"/></td>
							<td style="color : white;" bgcolor="{$HTMLCode}"><xsl:value-of select="./cc:B"/></td>
						</xsl:when>
						<xsl:otherwise>
							<td bgcolor="{$HTMLCode}"><xsl:value-of select="./cc:R"/></td>							
							<td bgcolor="{$HTMLCode}"><xsl:value-of select="./cc:G"/></td>
							<td bgcolor="{$HTMLCode}"><xsl:value-of select="./cc:B"/></td>
						</xsl:otherwise>
					</xsl:choose>
					</xsl:for-each>
				</xsl:if>
			   <xsl:if test="not($SRGB_ext)">
						<td> n/a </td>
						<td> n/a </td>
						<td> n/a </td>
				</xsl:if>			   		   
		         <xsl:if test="$LAB_ext"> 
					<xsl:for-each select="cc:ColorCIELab[1]">
					  <xsl:variable name="CXF3CIELab_L" select="./cc:L"/>
					  <xsl:variable name="CXF3CIELab_A" select="./cc:A"/>
					  <xsl:variable name="CXF3CIELab_B" select="./cc:B"/>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF3CIELab_L,"###.00")'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF3CIELab_A,"###.00")'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF3CIELab_B,"###.00")'/></td>
					</xsl:for-each>
				</xsl:if>
			   <xsl:if test="not($LAB_ext)">
						<td> n/a </td>
						<td> n/a </td>
						<td> n/a </td>
				</xsl:if>			   		   
		         <xsl:if test="$XYZ_ext"> 
					<xsl:for-each select="cc:ColorCIEXYZ[1]">
					  <xsl:variable name="CXF3CIEXYZ_X" select="./cc:X"/>
					  <xsl:variable name="CXF3CIEXYZ_Y" select="./cc:Y"/>
					  <xsl:variable name="CXF3CIEXYZ_Z" select="./cc:Z"/>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF3CIEXYZ_X,"###.00")'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF3CIEXYZ_Y,"###.00")'/></td>
						<td style="white-space: nowrap;"><xsl:value-of select='format-number($CXF3CIEXYZ_Z,"###.00")'/></td>
					</xsl:for-each>
				</xsl:if>
			   <xsl:if test="not($XYZ_ext)">
						<td> n/a </td>
						<td> n/a </td>
						<td> n/a </td>
				</xsl:if>			   		   
		</xsl:for-each>
		<xsl:if test="$DeviceColorValues_ext"> 		
		  <xsl:for-each select="cc:DeviceColorValues">
		      <xsl:variable name="CMYK_ext" select="cc:ColorCMYK[1]"/>
		         <xsl:if test="$CMYK_ext"> 
					<xsl:for-each select="cc:ColorCMYK[1]">
						<td style="white-space: nowrap;"><xsl:value-of select="./cc:Cyan"/></td>
						<td style="white-space: nowrap;"><xsl:value-of select="./cc:Magenta"/></td>
						<td style="white-space: nowrap;"><xsl:value-of select="./cc:Yellow"/></td>
						<td style="white-space: nowrap;"><xsl:value-of select="./cc:Black"/></td>
					</xsl:for-each>
				</xsl:if>
			   <xsl:if test="not($CMYK_ext)">
						<td> n/a </td>
						<td> n/a </td>
						<td> n/a </td>
						<td> n/a </td>
				</xsl:if>			   		   
		</xsl:for-each>
		</xsl:if>
		<xsl:if test="not($DeviceColorValues_ext)">
						<td> n/a </td>
						<td> n/a </td>
						<td> n/a </td>
						<td> n/a </td>
		</xsl:if>			   		   
			<xsl:for-each select="cc:ColorValues">
		      <xsl:variable name="SPECTRAL_ext" select="cc:ReflectanceSpectrum[1]"/>
		         <xsl:if test="$SPECTRAL_ext"> 
					<xsl:for-each select="cc:ReflectanceSpectrum[1]">
						<td style="white-space: nowrap;"><xsl:value-of select="current()"/></td>
					</xsl:for-each>
				</xsl:if>
			   <xsl:if test="not($SPECTRAL_ext)">
						<td> n/a </td>
				</xsl:if>			   		   
		</xsl:for-each>
	</tr>
      </xsl:for-each>
    </table>
    <xsl:for-each select="cc:Object[1]/cc:DeviceColorValues/cc:ColorHTML">
     <xsl:for-each select="id(@ColorSpecification)">
		<b>Color Patches rendered for illuminant </b>     
		 <b><xsl:value-of select="./cc:TristimulusSpec/cc:Illuminant"/></b>
     </xsl:for-each>
    </xsl:for-each>
</xsl:template>
<xsl:template match="cc:Resources/cc:ColorSpecificationCollection">
<h4 style="text-decoration : underline;">Color Specifications:</h4>
	<xsl:for-each select="cc:ColorSpecification">
		<h5>Id=<xsl:value-of select="@Id"/></h5>
	</xsl:for-each>
</xsl:template>
<xsl:template match="cc:Resources/cc:ProfileCollection">
<h4 style="text-decoration : underline;">Profiles:</h4>
	<xsl:for-each select="cc:Profile">
		<h5>Id=<xsl:value-of select="@Id"/>, (<xsl:value-of select="@Direction"/>)</h5>
	</xsl:for-each>
</xsl:template>

<xsl:template name="RGBtoHEX">
    <xsl:param name="dRed" />
    <xsl:param name="dGreen" />
    <xsl:param name="dBlue" />
	<xsl:variable name="RedCode">
	<xsl:choose>
		<xsl:when test="$dRed &lt; 17">0<xsl:call-template name="toHex"><xsl:with-param name="decimalNumber" select="$dRed"/></xsl:call-template>
		</xsl:when>
		<xsl:otherwise>	
	<xsl:call-template name="toHex">
			<xsl:with-param name="decimalNumber" select="$dRed"/>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="GrnCode">
	<xsl:choose>
		<xsl:when test="$dGreen &lt; 17">0<xsl:call-template name="toHex"><xsl:with-param name="decimalNumber" select="$dGreen"/></xsl:call-template>
		</xsl:when>
		<xsl:otherwise>	
	<xsl:call-template name="toHex">
			<xsl:with-param name="decimalNumber" select="$dGreen"/>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="BluCode" >
	<xsl:choose>
		<xsl:when test="$dBlue &lt; 17">0<xsl:call-template name="toHex"><xsl:with-param name="decimalNumber" select="$dBlue"/></xsl:call-template>
		</xsl:when>
		<xsl:otherwise>	
	<xsl:call-template name="toHex">
			<xsl:with-param name="decimalNumber" select="$dBlue"/>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="theCode" select="concat($RedCode,$GrnCode,$BluCode)"/>
	<xsl:value-of select="$theCode"/>
</xsl:template>
<xsl:variable name="hexDigits" select="'0123456789abcdef'" />

<xsl:template name="toHex">
    <xsl:param name="decimalNumber" />
     <xsl:if test="$decimalNumber >= 16">
       <xsl:call-template name="toHex">
         <xsl:with-param name="decimalNumber"
 select="floor($decimalNumber div 16)" />
       </xsl:call-template>
     </xsl:if>
     <xsl:variable name="Result" select="substring($hexDigits, 
 ($decimalNumber mod 16) + 1, 1)"/>
	<xsl:value-of select="$Result"/>
 </xsl:template>
</xsl:stylesheet>
