<?xml version="1.0" encoding="utf-8" ?>

<xsl:stylesheet id="PlateFormat 1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:exslt="http://exslt.org/common" version="1.0">
    <xsl:output method="xml" indent="yes" />
	
	<xsl:template match="/">
		<xsl:text disable-output-escaping="yes">&lt;Workbook xmlns=&quot;urn:schemas-microsoft-com:office:spreadsheet&quot;&gt;</xsl:text>
		

		<xsl:for-each select="MasterPlexPlateData">
			<xsl:variable name="numrows">
					<xsl:value-of select="Row"/>
				</xsl:variable>
				<xsl:variable name="name">
					<xsl:text>Out</xsl:text>
				</xsl:variable>
				<xsl:variable name="numcols">
					<xsl:value-of select="Col"/>
				</xsl:variable>
			
			<xsl:element name="Worksheet">
				<xsl:attribute name="ss:Name">
                    <xsl:value-of select="$name" />
                </xsl:attribute>
			

				<Table>
					<!-- Header information -->
					
						<Row>
                        <Cell ss:Index="6" >
                            <Data ss:Type="String">MasterPlex QT Plate Format Report</Data>
                        </Cell>
                        
                    </Row>
                    <Row>
                        <Cell ss:Index="1" >
                            <Data ss:Type="String">Report Date: <xsl:value-of select="/MasterPlexPlateData/AnlyDate" /></Data>
                        </Cell>
                        <Cell ss:Index="9">
                            <Data ss:Type="String">Run Date: <xsl:value-of select="/MasterPlexPlateData/RunDate" />
                                
                            </Data>
                        </Cell>
                    </Row>
                     <Row>
                        <Cell ss:Index="1" >
                            <Data ss:Type="String">Report Time: <xsl:value-of select="/MasterPlexPlateData/AnlyTime" /></Data>
                        </Cell>
                        <Cell ss:Index="9">
                            <Data ss:Type="String">Run Time: <xsl:value-of select="/MasterPlexPlateData/RunTime" />
                                
                            </Data>
                        </Cell>
                    </Row>
                    <Row>
                        <Cell ss:Index="1" >
                            <Data ss:Type="String">Data File: <xsl:value-of select="/MasterPlexPlateData/FileName" /></Data>
                        </Cell>
                        <Cell ss:Index="9">
                            <Data ss:Type="String">Hardware Serial No: <xsl:value-of select="/MasterPlexPlateData/LXHWSN" />
                                
                            </Data>
                        </Cell>
                    </Row>
                   <Row>
                        <Cell ss:Index="1" >
                            <Data ss:Type="String">Plate Name: <xsl:value-of select="/MasterPlexPlateData/PlateName" /></Data>
                        </Cell>
                        <Cell ss:Index="9">
                            <Data ss:Type="String">Operator: <xsl:value-of select="/MasterPlexPlateData/Operator" />
                                
                            </Data>
                        </Cell>
                    </Row>
                    <Row>
                        <Cell ss:Index="1" >
                            <Data ss:Type="String">MasterPlex QT Version: 4.0.4.38</Data>
                        </Cell>
                        <Cell ss:Index="9">
                            <Data ss:Type="String">Analyst: 
                                
                            </Data>
                        </Cell>
                    </Row>
					<!-- end Header information -->
					<Row>
                        <Cell ss:Index="7" >
                            <Data ss:Type="String">Data Type: MFI</Data>
                        </Cell>
                        
                    </Row>
                 <xsl:for-each select="BeadInfo">
                 <xsl:variable name="AnalyteName">
                <xsl:value-of select="@beadname" />
            </xsl:variable>
            
            <Row>
                        <Cell ss:Index="7" >
                            <Data ss:Type="String">Analyte: <xsl:value-of select="$AnalyteName" /></Data>
                        </Cell>
                        <Cell ss:Index="13" >
                            <Data ss:Type="String">Background: <xsl:value-of select="@bkgvalue" /></Data>
                        </Cell>
                    </Row>
			
			<xsl:variable name="BeadID">
                <xsl:value-of select="@id" />
            </xsl:variable>   
				<xsl:call-template name="MFI">
						<xsl:with-param name="rowcounter" select="1"/>
						<xsl:with-param name="maxrows" select="$numrows"/>
						<xsl:with-param name="beadid" select="$BeadID"/>
					</xsl:call-template>
					
			</xsl:for-each>	
			<Row>
                        <Cell ss:Index="7" >
                            <Data ss:Type="String">Data Type: Concentration</Data>
                        </Cell>
                        
                    </Row>
					
          <xsl:for-each select="BeadInfo">
                 <xsl:variable name="AnalyteName">
                <xsl:value-of select="@beadname" />
            </xsl:variable>
            
            <Row>
                        <Cell ss:Index="7" >
                            <Data ss:Type="String">Analyte: <xsl:value-of select="$AnalyteName" /></Data>
                        </Cell>
                        
                    </Row>
			
			<xsl:variable name="BeadID">
                <xsl:value-of select="@id" />
            </xsl:variable>   
				<xsl:call-template name="Conc">
						<xsl:with-param name="rowcounter" select="1"/>
						<xsl:with-param name="maxrows" select="$numrows"/>
						<xsl:with-param name="beadid" select="$BeadID"/>
					</xsl:call-template>
					
			</xsl:for-each>	
					
					
					
					<Row>
                        <Cell ss:Index="7" >
                            <Data ss:Type="String">Data Type: BeadCount</Data>
                        </Cell>
                        
                    </Row>
					
          <xsl:for-each select="BeadInfo">
                 <xsl:variable name="AnalyteName">
                <xsl:value-of select="@beadname" />
            </xsl:variable>
            
            <Row>
                        <Cell ss:Index="7" >
                            <Data ss:Type="String">Analyte: <xsl:value-of select="$AnalyteName" /></Data>
                        </Cell>
                        
                    </Row>
			
			<xsl:variable name="BeadID">
                <xsl:value-of select="@id" />
            </xsl:variable>   
				<xsl:call-template name="BeadCount">
						<xsl:with-param name="rowcounter" select="1"/>
						<xsl:with-param name="maxrows" select="$numrows"/>
						<xsl:with-param name="beadid" select="$BeadID"/>
					</xsl:call-template>
					
			</xsl:for-each>	
					
	
				</Table>
				
				<xsl:variable name="colOffset">
					<xsl:value-of select="$numcols - 1"/>
				</xsl:variable>
				<xsl:variable name="rowOffset">
					<xsl:value-of select="$numrows - 1"/>
				</xsl:variable>
				<xsl:variable name="colStart">
					<xsl:value-of select="3"/>
				</xsl:variable>
				<xsl:variable name="colEnd">
					<xsl:value-of select="$colOffset + $colStart"/>
				</xsl:variable>
				<xsl:variable name="sectionjump">
					<xsl:value-of select="2"/>
				</xsl:variable>
				
				<xsl:variable name="plateRowStart">
					<xsl:value-of select="7"/>
				</xsl:variable>
				<xsl:variable name="plateRowEnd">
					<xsl:value-of select="$plateRowStart + $rowOffset"/>
				</xsl:variable>
				<xsl:variable name="bcRowStart">
					<xsl:value-of select="$plateRowEnd + $sectionjump"/>
				</xsl:variable>
				<xsl:variable name="bcRowEnd">
					<xsl:value-of select="$bcRowStart + $rowOffset"/>
				</xsl:variable>
				<xsl:variable name="mfiRowStart">
					<xsl:value-of select="$bcRowEnd + $sectionjump"/>
				</xsl:variable>
				<xsl:variable name="mfiRowEnd">
					<xsl:value-of select="$mfiRowStart + $rowOffset"/>
				</xsl:variable>
				<xsl:variable name="avgbkgRowStart">
					<xsl:value-of select="$mfiRowEnd + $sectionjump"/>
				</xsl:variable>
				<xsl:variable name="avgbkgRowEnd">
					<xsl:value-of select="$avgbkgRowStart + $rowOffset"/>
				</xsl:variable>
				<xsl:variable name="signalRowStart">
					<xsl:value-of select="$avgbkgRowEnd + $sectionjump"/>
				</xsl:variable>
				<xsl:variable name="signalRowEnd">
					<xsl:value-of select="$signalRowStart + $rowOffset"/>
				</xsl:variable>
				<xsl:variable name="stddevRowStart">
					<xsl:value-of select="$signalRowEnd + $sectionjump"/>
				</xsl:variable>
				<xsl:variable name="stddevRowEnd">
					<xsl:value-of select="$stddevRowStart + $rowOffset"/>
				</xsl:variable>
				<xsl:variable name="cvRowStart">
					<xsl:value-of select="$stddevRowEnd + $sectionjump"/>
				</xsl:variable>
				<xsl:variable name="cvRowEnd">
					<xsl:value-of select="$cvRowStart + $rowOffset"/>
				</xsl:variable>
				<xsl:variable name="normRowStart">
					<xsl:value-of select="$cvRowEnd + $sectionjump"/>
				</xsl:variable>
				<xsl:variable name="normRowEnd">
					<xsl:value-of select="$normRowStart + $rowOffset"/>
				</xsl:variable>
				
				
				
			</xsl:element>	
		</xsl:for-each>
		<xsl:text disable-output-escaping="yes">&lt;/Workbook&gt;</xsl:text>
	</xsl:template>
	
	<xsl:template name="header_cols">
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<Cell ss:Index="{$colcounter + 2}" >
				<Data ss:Type="Number">
					<xsl:value-of select="$colcounter"/>
				</Data>
			</Cell>
			<xsl:call-template name="header_cols">
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="PlateMap">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:variable name="character">
					<xsl:value-of select="$rowcounter + 64"/>
				</xsl:variable>
				<xsl:if test="$rowcounter = '1'">
					<Cell ss:Index="1">
						<Data ss:Type="String">Plate Map</Data>
					</Cell>
				</xsl:if>
				<Cell ss:Index="2" ss:Formula="=CHAR({$character})">
					<Data ss:Type="String"/>
				</Cell>
				<xsl:call-template name="PlateMap_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="PlateMap">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="BeadCount">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:call-template name="RowName">
				  <xsl:with-param name="name" select="$rowcounter"/>
				  </xsl:call-template>
				<xsl:call-template name="BeadCount_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="BeadCount">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="MFI">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
			<!--	<xsl:variable name="character">
					<xsl:value-of select="$rowcounter + 64"/>
				</xsl:variable>
				
					
				<Cell ss:Index="2" ss:Formula="=CHAR({$character})">
					<Data ss:Type="String"/>
				</Cell> -->
				<xsl:call-template name="RowName">
				  <xsl:with-param name="name" select="$rowcounter"/>
				  </xsl:call-template>
				<xsl:call-template name="MFI_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="MFI">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="Conc">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:call-template name="RowName">
				  <xsl:with-param name="name" select="$rowcounter"/>
				  </xsl:call-template>
				<xsl:call-template name="Conc_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="Conc">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="Avg-Bkg">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:variable name="character">
					<xsl:value-of select="$rowcounter + 64"/>
				</xsl:variable>
				<xsl:if test="$rowcounter = '1'">
					<Cell ss:Index="1">
						<Data ss:Type="String">Avg-Bkg</Data>
					</Cell>
				</xsl:if>
				<Cell ss:Index="2" ss:Formula="=CHAR({$character})">
					<Data ss:Type="String"/>
				</Cell>
				<xsl:call-template name="Avg-Bkg_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="Avg-Bkg">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="SignalNoise">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:variable name="character">
					<xsl:value-of select="$rowcounter + 64"/>
				</xsl:variable>
				<xsl:if test="$rowcounter = '1'">
					<Cell ss:Index="1">
						<Data ss:Type="String">Signal:Noise</Data>
					</Cell>
				</xsl:if>
				<Cell ss:Index="2" ss:Formula="=CHAR({$character})">
					<Data ss:Type="String"/>
				</Cell>
				<xsl:call-template name="SignalNoise_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="SignalNoise">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="StdDev">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:variable name="character">
					<xsl:value-of select="$rowcounter + 64"/>
				</xsl:variable>
				<xsl:if test="$rowcounter = '1'">
					<Cell ss:Index="1">
						<Data ss:Type="String">Standard Deviation</Data>
					</Cell>
				</xsl:if>
				<Cell ss:Index="2" ss:Formula="=CHAR({$character})">
					<Data ss:Type="String"/>
				</Cell>
				<xsl:call-template name="StdDev_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="StdDev">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="CV">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:variable name="character">
					<xsl:value-of select="$rowcounter + 64"/>
				</xsl:variable>
				<xsl:if test="$rowcounter = '1'">
					<Cell ss:Index="1">
						<Data ss:Type="String">%CV</Data>
					</Cell>
				</xsl:if>
				<Cell ss:Index="2" ss:Formula="=CHAR({$character})">
					<Data ss:Type="String"/>
				</Cell>
				<xsl:call-template name="CV_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="CV">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="Normalized">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="maxrows" select="1"/>
		<xsl:param name="beadid" select="1"/>
		
		<xsl:variable name="start">
			<xsl:value-of select="$rowcounter - 1"/>
		</xsl:variable>
		<xsl:variable name="columns">
			<xsl:value-of select="/MasterPlexPlateData/Col"/>
		</xsl:variable>
		
		<xsl:if test="$start = '0'">
			<Row>
				<xsl:call-template name="header_cols">
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
				</xsl:call-template>
			</Row>
		</xsl:if>
	
		<xsl:if test="$rowcounter &lt; $maxrows + 1">
			<Row>
				<xsl:variable name="character">
					<xsl:value-of select="$rowcounter + 64"/>
				</xsl:variable>
				<xsl:if test="$rowcounter = '1'">
					<Cell ss:Index="1">
						<Data ss:Type="String">Normalized</Data>
					</Cell>
				</xsl:if>
				<Cell ss:Index="2" ss:Formula="=CHAR({$character})">
					<Data ss:Type="String"/>
				</Cell>
				<xsl:call-template name="Normalized_Row">
					<xsl:with-param name="rowcounter" select="$rowcounter"/>
					<xsl:with-param name="colcounter" select="1"/>
					<xsl:with-param name="maxcols" select="$columns"/>
					<xsl:with-param name="beadid" select="$beadid"/>
				</xsl:call-template>
			</Row>
			<xsl:call-template name="Normalized">
				<xsl:with-param name="rowcounter" select="$rowcounter + 1"/>
				<xsl:with-param name="maxrows" select="$maxrows"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="PlateMap_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:choose>
							<xsl:when test="$rowcounter = '1'">
								<xsl:choose>
									<!-- first cell -->
									<xsl:when test="$colcounter = '1'">
										<Cell ss:Index="{$columnID + $offset}" >
											<Data ss:Type="String">
												<xsl:value-of select="@name" />
											</Data>
										</Cell>
									</xsl:when>
									<!-- middle cells -->
									<xsl:otherwise>
										<Cell ss:Index="{$columnID + $offset}" >
											<Data ss:Type="String">
												<xsl:value-of select="@name" />
											</Data>
										</Cell>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:when>
							<xsl:when test="$rowcounter = $numrows">
								<xsl:choose>
									<!-- first cell -->
									<xsl:when test="$colcounter = '1'">
										<Cell ss:Index="{$columnID + $offset}" >
											<Data ss:Type="String">
												<xsl:value-of select="@name" />
											</Data>
										</Cell>
									</xsl:when>
									<!-- middle cells -->
									<xsl:otherwise>
										<Cell ss:Index="{$columnID + $offset}" >
											<Data ss:Type="String">
												<xsl:value-of select="@name" />
											</Data>
										</Cell>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:when>
							<xsl:otherwise>
								<xsl:choose>
									<!-- first cell -->
									<xsl:when test="$colcounter = '1'">
										<Cell ss:Index="{$columnID + $offset}" >
											<Data ss:Type="String">
												<xsl:value-of select="@name" />
											</Data>
										</Cell>
									</xsl:when>
									<!-- middle cells -->
									<xsl:otherwise>
										<Cell ss:Index="{$columnID + $offset}" >
											<Data ss:Type="String">
												<xsl:value-of select="@name" />
											</Data>
										</Cell>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="PlateMap_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="BeadCount_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@count" />
												</Data>
											</Cell>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@count" />
												</Data>
											</Cell>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@count" />
												</Data>
											</Cell>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@count" />
												</Data>
											</Cell>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@count" />
												</Data>
											</Cell>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@count" />
												</Data>
											</Cell>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="BeadCount_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="MFI_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@mfi" />
												</Data>
											</Cell>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@mfi" />
												</Data>
											</Cell>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@mfi" />
												</Data>
											</Cell>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@mfi" />
												</Data>
											</Cell>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@mfi" />
												</Data>
											</Cell>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<Cell ss:Index="{$columnID + $offset}" >
												<Data ss:Type="Number">
													<xsl:value-of select="@mfi" />
												</Data>
											</Cell>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="MFI_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
<xsl:template name="Conc_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
										<xsl:call-template name="stringtest">
											<xsl:with-param name="string" select="@conc" />
											<xsl:with-param name="columnID" select="$columnID" />
											<xsl:with-param name="offset" select="$offset" />
										</xsl:call-template>
											
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:call-template name="stringtest">
											<xsl:with-param name="string" select="@conc" />
											<xsl:with-param name="columnID" select="$columnID" />
											<xsl:with-param name="offset" select="$offset" />
										</xsl:call-template>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
										<xsl:call-template name="stringtest">
											<xsl:with-param name="string" select="@conc" />
											<xsl:with-param name="columnID" select="$columnID" />
											<xsl:with-param name="offset" select="$offset" />
										</xsl:call-template>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:call-template name="stringtest">
											<xsl:with-param name="string" select="@conc" />
											<xsl:with-param name="columnID" select="$columnID" />
											<xsl:with-param name="offset" select="$offset" />
										</xsl:call-template>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:call-template name="stringtest">
											<xsl:with-param name="string" select="@conc" />
											<xsl:with-param name="columnID" select="$columnID" />
											<xsl:with-param name="offset" select="$offset" />
										</xsl:call-template>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
										<xsl:call-template name="stringtest">
											<xsl:with-param name="string" select="@conc" />
											<xsl:with-param name="columnID" select="$columnID" />
											<xsl:with-param name="offset" select="$offset" />
										</xsl:call-template>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="Conc_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="Avg-Bkg_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@sampleavg = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@sampleavg = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@sampleavg" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@sampleavg = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@sampleavg = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@sampleavg" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@sampleavg = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@sampleavg = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@sampleavg" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@sampleavg = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@sampleavg = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@sampleavg" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@sampleavg = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@sampleavg = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@sampleavg" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@sampleavg = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@sampleavg = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@sampleavg" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="Avg-Bkg_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="SignalNoise_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:variable name="bkgavg">
				<xsl:value-of select="/MasterPlexPlateData/BeadInfo[@id=$beadid]/@bkgvalue"/>
			</xsl:variable>
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:variable name="sampleavg1">
								<xsl:call-template name="Scientific">
									<xsl:with-param name="Num" select="@sampleavg" />
								</xsl:call-template>
							</xsl:variable>
							<xsl:variable name="result">
								<xsl:value-of select="$sampleavg1 div $bkgavg"/>
							</xsl:variable>
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="$result = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="$result = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$result" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$result = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="$result = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$result" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="$result = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="$result = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$result" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$result = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="$result = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$result" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="$result = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="$result = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$result" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$result = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="$result = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$result" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="SignalNoise_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="StdDev_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@resstddev = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@resstddev = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@resstddev" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@resstddev = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@resstddev = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@resstddev" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@resstddev = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@resstddev = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@resstddev" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@resstddev = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@resstddev = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@resstddev" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@resstddev = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@resstddev = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@resstddev" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@resstddev = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@resstddev = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@resstddev" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="StdDev_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="CV_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@samplecv = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@samplecv = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@samplecv" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@samplecv = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@samplecv = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@samplecv" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@samplecv = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@samplecv = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@samplecv" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@samplecv = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@samplecv = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@samplecv" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@samplecv = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@samplecv = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@samplecv" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@samplecv = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@samplecv = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@samplecv" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="CV_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="Normalized_Row">
		<xsl:param name="rowcounter" select="1"/>
		<xsl:param name="colcounter" select="1"/>
		<xsl:param name="maxcols" select="1"/>
		<xsl:param name="beadid" select="1"/>
		<xsl:variable name="offset">
			<xsl:value-of select="2"/>
		</xsl:variable>
		<xsl:variable name="numrows">
			<xsl:value-of select="/MasterPlexPlateData/Row"/>
		</xsl:variable>
				
		<xsl:if test="$colcounter &lt; $maxcols + 1">
			<xsl:choose>
				<xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
					<xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
						<xsl:variable name="columnID">
							<xsl:value-of select="@colid"/>
						</xsl:variable>
						<xsl:for-each select="Bead[@id=$beadid]">
							<xsl:choose>
								<xsl:when test="$rowcounter = '1'">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@normalized = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@normalized = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@normalized" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@normalized = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@normalized = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@normalized" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:when test="$rowcounter = $numrows">
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@normalized = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@normalized = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@normalized" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@normalized = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@normalized = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@normalized" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:when>
								<xsl:otherwise>
									<xsl:choose>
										<!-- first cell -->
										<xsl:when test="$colcounter = '1'">
											<xsl:choose>
												<xsl:when test="@normalized = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@normalized = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@normalized" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="@normalized = 'NaN'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">NaN</Data>
													</Cell>
												</xsl:when>
												<xsl:when test="@normalized = 'Infinity'">
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="String">Infinity</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="@normalized" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:otherwise>
									</xsl:choose>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$rowcounter = '1'">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="$rowcounter = $numrows">
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="$colcounter = $maxcols">
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:when>
								<xsl:otherwise>
									<Cell ss:Index="{$colcounter + $offset}" >
										<Data ss:Type="String">Empty</Data>
									</Cell>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="Normalized_Row">
				<xsl:with-param name="rowcounter" select="$rowcounter"/>
				<xsl:with-param name="colcounter" select="$colcounter + 1"/>
				<xsl:with-param name="maxcols" select="$maxcols"/>
				<xsl:with-param name="beadid" select="$beadid"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="Scientific">
	<xsl:param name="Num"/>
	<xsl:if test="boolean(number(substring-after($Num,'E')))">
		<xsl:call-template name="Scientific_Helper">
			<xsl:with-param name="m" select="substring-before($Num,'E')"/>
			<xsl:with-param name="e" select="substring-after($Num,'E')"/>
		</xsl:call-template>
	</xsl:if>
	<xsl:if test="not(boolean(number(substring-after($Num,'E'))))">
		<xsl:value-of select='format-number($Num, "#.00")'/>
	</xsl:if>
</xsl:template>
<xsl:template name="RowName">
  <xsl:param name="name"/>
  <xsl:choose>
  <xsl:when test="$name =1"><Cell ss:Index="2"><Data ss:Type="String">A</Data></Cell></xsl:when>
  <xsl:when test="$name =2"><Cell ss:Index="2"><Data ss:Type="String">B</Data></Cell></xsl:when>
  <xsl:when test="$name =3"><Cell ss:Index="2"><Data ss:Type="String">C</Data></Cell></xsl:when>
  <xsl:when test="$name =4"><Cell ss:Index="2"><Data ss:Type="String">D</Data></Cell></xsl:when>
  <xsl:when test="$name =5"><Cell ss:Index="2"><Data ss:Type="String">E</Data></Cell></xsl:when>
  <xsl:when test="$name =6"><Cell ss:Index="2"><Data ss:Type="String">F</Data></Cell></xsl:when>
  <xsl:when test="$name =7"><Cell ss:Index="2"><Data ss:Type="String">G</Data></Cell></xsl:when>
  <xsl:when test="$name =8"><Cell ss:Index="2"><Data ss:Type="String">H</Data></Cell></xsl:when>
  <xsl:when test="$name =9"><Cell ss:Index="2"><Data ss:Type="String">I</Data></Cell></xsl:when>
  <xsl:when test="$name =10"><Cell ss:Index="2"><Data ss:Type="String">J</Data></Cell></xsl:when>
  <xsl:when test="$name =11"><Cell ss:Index="2"><Data ss:Type="String">K</Data></Cell></xsl:when>
  <xsl:when test="$name =12"><Cell ss:Index="2"><Data ss:Type="String">L</Data></Cell></xsl:when>
  <xsl:when test="$name =13"><Cell ss:Index="2"><Data ss:Type="String">M</Data></Cell></xsl:when>
  <xsl:when test="$name =14"><Cell ss:Index="2"><Data ss:Type="String">N</Data></Cell></xsl:when>
  <xsl:when test="$name =15"><Cell ss:Index="2"><Data ss:Type="String">O</Data></Cell></xsl:when>
  <xsl:when test="$name =16"><Cell ss:Index="2"><Data ss:Type="String">P</Data></Cell></xsl:when>
  <xsl:when test="$name =17"><Cell ss:Index="2"><Data ss:Type="String">Q</Data></Cell></xsl:when>
  <xsl:when test="$name =18"><Cell ss:Index="2"><Data ss:Type="String">R</Data></Cell></xsl:when>
  <xsl:when test="$name =19"><Cell ss:Index="2"><Data ss:Type="String">S</Data></Cell></xsl:when>
  <xsl:when test="$name =20"><Cell ss:Index="2"><Data ss:Type="String">T</Data></Cell></xsl:when>
  <xsl:when test="$name =21"><Cell ss:Index="2"><Data ss:Type="String">U</Data></Cell></xsl:when>
  <xsl:when test="$name =22"><Cell ss:Index="2"><Data ss:Type="String">V</Data></Cell></xsl:when>
  <xsl:when test="$name =23"><Cell ss:Index="2"><Data ss:Type="String">W</Data></Cell></xsl:when>
  <xsl:when test="$name =24"><Cell ss:Index="2"><Data ss:Type="String">X</Data></Cell></xsl:when>
  <xsl:when test="$name =25"><Cell ss:Index="2"><Data ss:Type="String">Y</Data></Cell></xsl:when>
  <xsl:when test="$name =26"><Cell ss:Index="2"><Data ss:Type="String">Z</Data></Cell></xsl:when>
  <xsl:when test="$name =27"><Cell ss:Index="2"><Data ss:Type="String">AA</Data></Cell></xsl:when>
  <xsl:when test="$name =28"><Cell ss:Index="2"><Data ss:Type="String">AB</Data></Cell></xsl:when>
  <xsl:when test="$name =29"><Cell ss:Index="2"><Data ss:Type="String">AC</Data></Cell></xsl:when>
  <xsl:when test="$name =30"><Cell ss:Index="2"><Data ss:Type="String">AD</Data></Cell></xsl:when>
  <xsl:when test="$name =31"><Cell ss:Index="2"><Data ss:Type="String">AE</Data></Cell></xsl:when>
  <xsl:when test="$name =32"><Cell ss:Index="2"><Data ss:Type="String">AF</Data></Cell></xsl:when>
  <xsl:when test="$name =33"><Cell ss:Index="2"><Data ss:Type="String">AG</Data></Cell></xsl:when>
  <xsl:when test="$name =34"><Cell ss:Index="2"><Data ss:Type="String">AH</Data></Cell></xsl:when>
  <xsl:when test="$name =35"><Cell ss:Index="2"><Data ss:Type="String">AI</Data></Cell></xsl:when>
  <xsl:when test="$name =36"><Cell ss:Index="2"><Data ss:Type="String">AJ</Data></Cell></xsl:when>
  <xsl:when test="$name =37"><Cell ss:Index="2"><Data ss:Type="String">AK</Data></Cell></xsl:when>
  <xsl:when test="$name =38"><Cell ss:Index="2"><Data ss:Type="String">AL</Data></Cell></xsl:when>
  <xsl:when test="$name =39"><Cell ss:Index="2"><Data ss:Type="String">AM</Data></Cell></xsl:when>
  <xsl:when test="$name =40"><Cell ss:Index="2"><Data ss:Type="String">AN</Data></Cell></xsl:when>
  <xsl:when test="$name =41"><Cell ss:Index="2"><Data ss:Type="String">AO</Data></Cell></xsl:when>
  <xsl:when test="$name =42"><Cell ss:Index="2"><Data ss:Type="String">AP</Data></Cell></xsl:when>
  <xsl:when test="$name =43"><Cell ss:Index="2"><Data ss:Type="String">AQ</Data></Cell></xsl:when>
  <xsl:when test="$name =44"><Cell ss:Index="2"><Data ss:Type="String">AR</Data></Cell></xsl:when>
  <xsl:when test="$name =45"><Cell ss:Index="2"><Data ss:Type="String">AS</Data></Cell></xsl:when>
  <xsl:when test="$name =46"><Cell ss:Index="2"><Data ss:Type="String">AT</Data></Cell></xsl:when>
  <xsl:when test="$name =47"><Cell ss:Index="2"><Data ss:Type="String">AU</Data></Cell></xsl:when>
  <xsl:when test="$name =48"><Cell ss:Index="2"><Data ss:Type="String">AV</Data></Cell></xsl:when>
  <xsl:when test="$name =49"><Cell ss:Index="2"><Data ss:Type="String">AW</Data></Cell></xsl:when>
  <xsl:when test="$name =50"><Cell ss:Index="2"><Data ss:Type="String">AX</Data></Cell></xsl:when>
  <xsl:when test="$name =51"><Cell ss:Index="2"><Data ss:Type="String">AY</Data></Cell></xsl:when>
  <xsl:when test="$name =52"><Cell ss:Index="2"><Data ss:Type="String">AZ</Data></Cell></xsl:when>
  
  </xsl:choose>
</xsl:template>
<xsl:template name="Scientific_Helper">
	<xsl:param name="m"/>
	<xsl:param name="e"/>
	<xsl:choose>
		<xsl:when test="$e = 0 or not(boolean($e))">
			<xsl:value-of select='format-number($m, "#.00")'/>
		</xsl:when>
		<xsl:when test="$e &gt; 0">
			<xsl:call-template name="Scientific_Helper">
				<xsl:with-param name="m" select="$m * 10"/>
				<xsl:with-param name="e" select="$e - 1"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$e &lt; 0">
			<xsl:call-template name="Scientific_Helper">
				<xsl:with-param name="m" select="$m div 10"/>
				<xsl:with-param name="e" select="$e + 1"/>
			</xsl:call-template>
		</xsl:when>
	</xsl:choose>
</xsl:template>
<xsl:template name="stringtest">
<xsl:param name="string"/>
<xsl:param name="columnID"/>
<xsl:param name="offset"/>

<xsl:choose>
<xsl:when test="starts-with($string, 'NaN')">
<Cell ss:Index="{$columnID + $offset}"><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, 'Infinity')">
<Cell ss:Index="{$columnID + $offset}"><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&lt;')">
<Cell ss:Index="{$columnID + $offset}"><Data ss:Type="String">OOR &lt;</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&gt;')">
<Cell ss:Index="{$columnID + $offset}"><Data ss:Type="String">OOR &gt;</Data></Cell>
</xsl:when>
<xsl:otherwise>
<Cell ss:Index="{$columnID + $offset}"><Data ss:Type="Number"><xsl:call-template name="Scientific">
						<xsl:with-param name="Num" select="$string" />
					</xsl:call-template></Data></Cell>
</xsl:otherwise>					
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


