<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet id="Data Type 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:key name="stdrep" match="MasterPlexPlateData/BeadInfo[1]/StandardCurve/DataSeries/StdWell" use="@stdconc" />
<xsl:template match="/">
<xsl:for-each select="MasterPlexPlateData">
 <xsl:variable name="analnumber">
 	<xsl:value-of select="count(BeadInfo)" />
 </xsl:variable>
 <xsl:variable name="screen">
 		<xsl:value-of select="$analnumber * 40" />
 </xsl:variable>	
<!-- Plate Map Variables -->
<xsl:variable name="numrows">
        <xsl:value-of select="Row" />
      </xsl:variable>
      <xsl:variable name="numcols">
        <xsl:value-of select="Col" />
      </xsl:variable>
           <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>
        
<!-- End Plate map variables -->
 <xsl:variable name="MasterPlexPlateData"> 
<xsl:copy-of select="/" />

<xsl:for-each select="BeadInfo/StandardCurve/DataSeries/StdWell[generate-id(.)=generate-id(key('stdrep', @stdconc)[1])]">
	<xsl:sort select="@stdconc" data-type="number" order="descending"/>
 
	
	<xsl:element name="StandardGroup2">
		<xsl:attribute name="name">S<xsl:number value ="position()"/></xsl:attribute>	
			<xsl:for-each select="key('stdrep', @stdconc)">	
		
		<xsl:element name="GroupWell">	
				
				
						<xsl:attribute name="id"><xsl:value-of select="@wellid"/></xsl:attribute>
					
					
			
					</xsl:element>
					</xsl:for-each>		
						</xsl:element>
			</xsl:for-each>					
					
 </xsl:variable> 
 <!-- <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="UTF-16"?&gt;</xsl:text>-->	
 <xsl:text disable-output-escaping="yes">&lt;Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"&gt;</xsl:text>
  <Styles>
 
 <Style ss:ID="count">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font/>
   <Interior ss:Color="#FF0000" ss:Pattern="Solid" />
   <NumberFormat/>
   <Protection/>
  </Style>
   <Style ss:ID="green">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font/>
   <Interior ss:Color="#00FF33" ss:Pattern="Solid" />
   <NumberFormat/>
   <Protection/>
  </Style>
       
 </Styles><!--<Workbook> -->
 <!--<xsl:for-each select="MasterPlexPlateData/BeadInfo">-->
  
<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name">SETUP, BEADS, STANDARDS</xsl:attribute>
			  
		 <Table>
		 <xsl:variable name="BeadID">
              <xsl:value-of select="@id" />
            </xsl:variable>
            <xsl:call-template name="PlateMap">
              <xsl:with-param name="rowcounter" select="1" />
              <xsl:with-param name="maxrows" select="$numrows" />
              <xsl:with-param name="beadid" select="$BeadID" />
             
            </xsl:call-template>
<!--End Plate Map -->  

<Row/>
<Row/>
<!--Total Beads -->
					<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="0"/>
						<xsl:with-param name="screen" select="$screen" />
					</xsl:call-template>
<!-- End Total Beads -->
<Row/>
<Row/>
<!-- STDS -->
<Row>
<Cell><Data ss:Type="String">Analytes</Data></Cell>
<Cell><Data ss:Type="String">Rsquared</Data></Cell>		
<Cell><Data ss:Type="String">Curve</Data></Cell>
<Cell><Data ss:Type="String">LLOD (Bkg + 2SD)</Data></Cell>				
	</Row>
<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo/StandardCurve"> 

			<xsl:variable name="bkg">
              <xsl:value-of select="../@bkgvalue" />
            </xsl:variable>
            <xsl:variable name="beadid">
              <xsl:value-of select="../@id" />
            </xsl:variable>
            <xsl:variable name="stddev">
              <xsl:value-of select="../../Well[@type=4]/Bead[@id=$beadid]/@resstddev" />
            </xsl:variable>
            <xsl:variable name="llod">
              <xsl:value-of  select="(3 * $stddev) + $bkg" />
            </xsl:variable>
		
		

				
					<xsl:variable name ="weight">
				<xsl:choose>
					<xsl:when test="@useweight = 1">	
						<xsl:choose>
							<xsl:when test="@weightmethod = 0">
								<xsl:value-of select="'1/Y^2'"/>
							</xsl:when>
							<xsl:when test="@weightmethod = 1">
								<xsl:value-of select="'1/Y'"/>
							</xsl:when>
							<xsl:when test="@weightmethod = 2">
								<xsl:value-of select="'1/X^2'"/>
							</xsl:when>
							<xsl:when test="@weightmethod = 3">
								<xsl:value-of select="'1/X'"/>
							</xsl:when>
							<xsl:otherwise></xsl:otherwise>
						</xsl:choose>	
					</xsl:when>
					<xsl:otherwise></xsl:otherwise>	
				</xsl:choose>	
			</xsl:variable>				
			<xsl:variable name ="equationname">
				<xsl:choose>
					<xsl:when test="@equationname = 'Five Parameter Logistics'">	
						<xsl:value-of select="'5PL'"/>
					</xsl:when>	
					<xsl:when test="@equationname = 'Four Parameter Logistics'">	
						<xsl:value-of select="'4PL'"/>
					</xsl:when>
					<xsl:otherwise><xsl:value-of select="@equationname"/></xsl:otherwise>	
				</xsl:choose></xsl:variable>	
	<Row>
	 	<Cell><Data ss:Type="String"><xsl:value-of select="../@beadname"/></Data></Cell>
	<!-- <Cell><Data ss:Type="String"><xsl:call-template name="Scientific">
	 	<xsl:with-param name="num" select="@rsquare" /></xsl:call-template></Data></Cell> -->
	 		<Cell><Data ss:Type="Number"><xsl:value-of select='format-number(@rsquare, "#.00000")'/></Data></Cell>
	 	
	 	<Cell><Data ss:Type="String"><xsl:value-of select="$equationname"/><xsl:text>,</xsl:text><xsl:value-of select="$weight"/></Data></Cell>
	<xsl:call-template name="stringtest">
                  
                  <xsl:with-param name="string" select="$llod" />
                </xsl:call-template>
	
	</Row>
	 			
</xsl:for-each>				


<!-- End STDS -->
   
	
	
	



	
	</Table>
	</xsl:element>		 
		
	
<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name">RAW MFI</xsl:attribute>	
	<Table>	
	<Row>
		<Cell><Data ss:Type="String">Sample</Data></Cell> 
		<Cell><Data ss:Type="String">Well</Data></Cell> 
		<Cell><Data ss:Type="String">Name</Data></Cell> 
		<Cell><Data ss:Type="String">Type</Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<Cell><Data ss:Type="String"><xsl:value-of select="@beadname"/></Data></Cell>
		</xsl:for-each>
	</Row>	
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/Well[@type!='0']">
		<Row>
	<!-- Fix Here-->	<Cell><Data ss:Type="Number"><xsl:value-of select="count(preceding-sibling::*[@wellid]) + 1"/>
</Data></Cell>
	
	
		<Cell><Data ss:Type="String"><xsl:value-of select="@addr"/></Data></Cell>
		<Cell><Data ss:Type="String"><xsl:value-of select="@name"/></Data></Cell>
				<xsl:variable name ="type">
		<xsl:variable name ="wellid"><xsl:value-of select="@wellid"/></xsl:variable>
				<xsl:choose>
					<xsl:when test="@type = 1">	
						
						<xsl:for-each select="../../StandardGroup2/GroupWell[@id=$wellid]">
						<xsl:value-of select="../@name"/>
						</xsl:for-each>
					</xsl:when>	
					<xsl:when test="@type = 2">
							<xsl:value-of select="'Unknown'"/>		
							</xsl:when>
							<xsl:when test="@type = 3">
									<xsl:value-of select="'Control'"/>	
							</xsl:when>
							<xsl:when test="@type = 4">
									<xsl:value-of select="'SB'"/>
							</xsl:when>
							
							<xsl:otherwise></xsl:otherwise>
						</xsl:choose>	
					
		</xsl:variable>
					
			
<!--Type-->		<Cell><Data ss:Type="String"><xsl:value-of select="$type"/> </Data></Cell>
			
		<xsl:for-each select="Bead">
		<xsl:variable name="mfi"><xsl:value-of select="@mfi"/></xsl:variable>
		<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
		 <xsl:variable name="background"><xsl:value-of select="../../BeadInfo[@id=$beadid]/@bkgvalue"/></xsl:variable>
		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="$mfi - $background" /></xsl:call-template>
			
		</xsl:for-each>
		</Row>
		</xsl:for-each>
		
		</Table>
	</xsl:element>
<!-- Average MFI -->
<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name">MFI AVERAGE</xsl:attribute>	
	<Table>		
		<Row>
		<Cell><Data ss:Type="String"></Data></Cell> 
		<Cell><Data ss:Type="String"></Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<Cell><Data ss:Type="String"><xsl:value-of select="@beadname"/></Data></Cell>
		</xsl:for-each>
	</Row>	
	<Row>
		<Cell><Data ss:Type="String">Group Name</Data></Cell> 
		<Cell><Data ss:Type="String">Wells</Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<Cell><Data ss:Type="String">MFI</Data></Cell>
	<!--	<Cell><Data ss:Type="String">%CV</Data></Cell>
		<Cell><Data ss:Type="String"><xsl:value-of select="StandardCurve/@stdunit"/></Data></Cell> -->
		</xsl:for-each>
	</Row>
	
	
	<!-- Start Unknown Replicates -->

	<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/UnknowGroupList/UnknowGroup">
	<Row>
	
<xsl:variable name="BeadNumber"><xsl:value-of select="@id"/></xsl:variable> 
	
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
      
        <Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each> 
       
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
		
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
						
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
				<!--	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template> -->
			<!--		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>			
						
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>		
							
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
				<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	
	</Row>
	</xsl:for-each>
	<!-- End Unknown Replicates -->
	
	
		<!-- Controls -->
	
	<xsl:for-each select="/MasterPlexPlateData/ControlGroupList/ControlGroup">
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<Row>
        
        <xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
      
        <Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each> 
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>	
			<!--		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template> -->
				<!--			
						
					<Cell><Data ss:Type="Number"><xsl:value-of select="@outlier"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>		
							
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
				<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Controls -->
	
		<!-- Standard Group 1-->
	<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/StandardGroup2">
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">
						<xsl:attribute name="expconc"><xsl:value-of select="/MasterPlexPlateData/BeadInfo/StandardCurve/DataSeries/StdWell[@wellid=$GroupWellID]/@stdconc"/></xsl:attribute>
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
					<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
		
		<Row>			  	
		
        <xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
      
        <Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each> 
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="/MasterPlexPlateData/Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>			
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
	
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>	
				<!--	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template> -->
        	<!--
					<Cell><Data ss:Type="Number"><xsl:value-of select="@outlier"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
						
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>				
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@expconc" /></xsl:call-template>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="(@conc div @expconc) * 100" /></xsl:call-template>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
					<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Standard Group -->	
	
	<!-- Background Group Replicate-->
	
	<xsl:for-each select="/MasterPlexPlateData/BkgGroupList/BkgGroup">
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo[@id=$beadid]/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<Row>
        
        <Cell><Data ss:Type="String">SB</Data></Cell>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@bkgvalue" /></xsl:call-template>	
				<!--	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template> -->
					
					
				
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	
	<!-- End Background Group -->
	

	
		</Table>
	</xsl:element>

<!-- End Average MFI -->	
		
<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name">RESULT</xsl:attribute>	
	<Table>			
		
		
		
		
		
	<Row>
		<Cell><Data ss:Type="String">Sample</Data></Cell> 
		<Cell><Data ss:Type="String">Well</Data></Cell> 
		<Cell><Data ss:Type="String">Name</Data></Cell> 
		<Cell><Data ss:Type="String">Type</Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<Cell><Data ss:Type="String"><xsl:value-of select="@beadname"/></Data></Cell>
		</xsl:for-each>
	</Row>
	<Row>
		<Cell><Data ss:Type="String"></Data></Cell> 
		<Cell><Data ss:Type="String"></Data></Cell> 
		<Cell><Data ss:Type="String"></Data></Cell> 
	<Cell><Data ss:Type="String"></Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo/StandardCurve">
		<Cell><Data ss:Type="String"><xsl:value-of select="@stdunit"/></Data></Cell>
		</xsl:for-each>
	</Row>	
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/Well[@type!='0']">
		<xsl:variable name ="type">
		<xsl:variable name ="wellid"><xsl:value-of select="@wellid"/></xsl:variable>
				<xsl:choose>
					<xsl:when test="@type = 1">	
						
						<xsl:for-each select="../../StandardGroup2/GroupWell[@id=$wellid]">
						<xsl:value-of select="../@name"/>
						</xsl:for-each>
					</xsl:when>	
					<xsl:when test="@type = 2">
							<xsl:value-of select="'Unknown'"/>		
							</xsl:when>
							<xsl:when test="@type = 3">
									<xsl:value-of select="'Control'"/>	
							</xsl:when>
							<xsl:when test="@type = 4">
									<xsl:value-of select="'SB'"/>
							</xsl:when>
							
							<xsl:otherwise></xsl:otherwise>
						</xsl:choose>	
					
		</xsl:variable>
		<Row>
		<Cell><Data ss:Type="Number"><xsl:value-of select="count(preceding-sibling::*[@wellid]) + 1"/>
</Data></Cell>
		<Cell><Data ss:Type="String"><xsl:value-of select="@addr"/></Data></Cell>
		<Cell><Data ss:Type="String"><xsl:value-of select="@name"/></Data></Cell>
		
							
		<Cell><Data ss:Type="String"><xsl:value-of select="$type"/></Data></Cell>
		
		<xsl:for-each select="Bead">
		
		
		<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template>
		
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constr" /></xsl:call-template>
		
  						</xsl:otherwise>
		</xsl:choose>
			
		</xsl:for-each>
		</Row>
		</xsl:for-each>		
		
			 
	</Table>
	</xsl:element>
<!-- Average Conc -->
<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name">RESULT AVERAGE</xsl:attribute>	
	<Table>		
		<Row>
		<Cell><Data ss:Type="String"></Data></Cell> 
		<Cell><Data ss:Type="String"></Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<Cell><Data ss:Type="String"><xsl:value-of select="@beadname"/></Data></Cell>
		</xsl:for-each>
	</Row>	
	<Row>
		<Cell><Data ss:Type="String">Group Name</Data></Cell> 
		<Cell><Data ss:Type="String">Wells</Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<!--	<Cell><Data ss:Type="String">MFI</Data></Cell>
	<Cell><Data ss:Type="String">%CV</Data></Cell>-->
		<Cell><Data ss:Type="String"><xsl:value-of select="StandardCurve/@stdunit"/></Data></Cell> 
		</xsl:for-each>
	</Row>
	
	
	<!-- Start Unknown Replicates -->

	<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/UnknowGroupList/UnknowGroup">
	<Row>
	
<xsl:variable name="BeadNumber"><xsl:value-of select="@id"/></xsl:variable> 
	
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
      
        <Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each> 
       
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
		
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
						
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>
				<!--	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template> -->
			<!--		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>			
						
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>		
							
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
				<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	
	</Row>
	</xsl:for-each>
	<!-- End Unknown Replicates -->
	
	
		<!-- Controls -->
	
	<xsl:for-each select="/MasterPlexPlateData/ControlGroupList/ControlGroup">
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<Row>
        
        <xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
      
        <Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each> 
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>	
			<!--		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template> -->
				<!--			
						
					<Cell><Data ss:Type="Number"><xsl:value-of select="@outlier"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>		
							
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
				<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Controls -->
	
		<!-- Standard Group 1-->
	<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/StandardGroup2">
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">
						<xsl:attribute name="expconc"><xsl:value-of select="/MasterPlexPlateData/BeadInfo/StandardCurve/DataSeries/StdWell[@wellid=$GroupWellID]/@stdconc"/></xsl:attribute>
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
					<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
		
		<Row>			  	
		
        <xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
      
        <Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each> 
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="/MasterPlexPlateData/Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>			
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
	
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>	
				<!--	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template> -->
        	<!--
					<Cell><Data ss:Type="Number"><xsl:value-of select="@outlier"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
						
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>				
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@expconc" /></xsl:call-template>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="(@conc div @expconc) * 100" /></xsl:call-template>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
					<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Standard Group -->	
	
	<!-- Background Group Replicate-->
	
	<xsl:for-each select="/MasterPlexPlateData/BkgGroupList/BkgGroup">
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo[@id=$beadid]/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<Row>
        
        <Cell><Data ss:Type="String">SB</Data></Cell>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template>	
				<!--	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template> -->
					
					
				
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	
	<!-- End Background Group -->
	

	
		</Table>
	</xsl:element>

<!-- End Average Conc -->		

		
	<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name">BEAD COUNT</xsl:attribute>	
		<Table>
		<Row>
		<Cell><Data ss:Type="String">Sample</Data></Cell> 
		<Cell><Data ss:Type="String">Well</Data></Cell> 
		<Cell><Data ss:Type="String">Name</Data></Cell> 
		<Cell><Data ss:Type="String">Type</Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<Cell><Data ss:Type="String"><xsl:value-of select="@beadname"/></Data></Cell>
		</xsl:for-each>
	</Row>

		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/Well[@type!='0']">
		<Row>
		<Cell><Data ss:Type="Number"><xsl:value-of select="count(preceding-sibling::*[@wellid]) + 1"/>
</Data></Cell>
		<Cell><Data ss:Type="String"><xsl:value-of select="@addr"/></Data></Cell>
		<Cell><Data ss:Type="String"><xsl:value-of select="@name"/></Data></Cell>
			<xsl:variable name ="type">
		<xsl:variable name ="wellid"><xsl:value-of select="@wellid"/></xsl:variable>
				<xsl:choose>
					<xsl:when test="@type = 1">	
						
						<xsl:for-each select="../../StandardGroup2/GroupWell[@id=$wellid]">
						<xsl:value-of select="../@name"/>
						</xsl:for-each>
					</xsl:when>	
					<xsl:when test="@type = 2">
							<xsl:value-of select="'Unknown'"/>		
							</xsl:when>
							<xsl:when test="@type = 3">
									<xsl:value-of select="'Control'"/>	
							</xsl:when>
							<xsl:when test="@type = 4">
									<xsl:value-of select="'SB'"/>
							</xsl:when>
							
							<xsl:otherwise></xsl:otherwise>
						</xsl:choose>	
					
		</xsl:variable>
		<Cell><Data ss:Type="String"><xsl:value-of select="$type"/></Data></Cell>
		<xsl:for-each select="Bead">
		
		<xsl:call-template name="stringtestcount"><xsl:with-param name="string" select="@count" />
		</xsl:call-template>	
		</xsl:for-each>
		</Row>
		</xsl:for-each>		
		
		
			 
		</Table>
	</xsl:element>	
	<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name">CV</xsl:attribute>	
		<Table>
		<Row>
		<Cell><Data ss:Type="String"></Data></Cell> 
		<Cell><Data ss:Type="String"></Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
		<Cell><Data ss:Type="String"><xsl:value-of select="@beadname"/></Data></Cell>
		</xsl:for-each>
	</Row>	
	<Row>
		<Cell><Data ss:Type="String">Group Name</Data></Cell> 
		<Cell><Data ss:Type="String">Wells</Data></Cell> 
		<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo">
	<Cell><Data ss:Type="String">%</Data></Cell>
		</xsl:for-each>
	</Row>
	
	
	<!-- Start Unknown Replicates -->

	<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/UnknowGroupList/UnknowGroup">
	<Row>
	
<xsl:variable name="BeadNumber"><xsl:value-of select="@id"/></xsl:variable> 
	
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	
        
        	<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
        	<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
		
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
						
					
					<xsl:call-template name="stringtestcv"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
			<!--		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>			
						
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>		
							
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
				<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	
	</Row>
	</xsl:for-each>
	<!-- End Unknown Replicates -->
	
	
		<!-- Controls -->
	
	<xsl:for-each select="/MasterPlexPlateData/ControlGroupList/ControlGroup">
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<Row>
        
        <xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
        	<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtestcv"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
				<!--			
						
					<Cell><Data ss:Type="Number"><xsl:value-of select="@outlier"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conavg" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>		
							
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
				<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Controls -->
	
		<!-- Standard Group 1-->
	<xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/StandardGroup2">
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">
						<xsl:attribute name="expconc"><xsl:value-of select="/MasterPlexPlateData/BeadInfo/StandardCurve/DataSeries/StdWell[@wellid=$GroupWellID]/@stdconc"/></xsl:attribute>
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
					<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
					<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
		
		<Row>			  	
		
        <xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell/GrpBead[1]">
        	<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell></xsl:for-each>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="/MasterPlexPlateData/Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>			
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
	
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
					<xsl:call-template name="stringtestcv"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
        	<!--
					<Cell><Data ss:Type="Number"><xsl:value-of select="@outlier"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@samplename"/></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg - @bkgvalue" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
						
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String">***</Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>				
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@expconc" /></xsl:call-template>	
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="(@conc div @expconc) * 100" /></xsl:call-template>	
					
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@conc" /></xsl:call-template>
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="String"></Data></Cell>	
					<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
					<Cell><Data ss:Type="Number"><xsl:value-of select="@count"/></Data></Cell> -->
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Standard Group -->	
	
	<!-- Background Group Replicate-->
	
	<xsl:for-each select="/MasterPlexPlateData/BkgGroupList/BkgGroup">
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<xsl:variable name="num_reps"><xsl:call-template name="sqrt"><xsl:with-param name="num" select="count(GroupWell)" /></xsl:call-template></xsl:variable>
		<xsl:for-each select="GroupWell[1]">
			

			<xsl:variable name="GroupWellID"><xsl:value-of select="@id"/></xsl:variable>
			<xsl:element name="GrpWell">
				<xsl:attribute name="num_reps"><xsl:value-of select="$num_reps"/></xsl:attribute>
				<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				<xsl:attribute name="pos"><xsl:value-of select="position()"/></xsl:attribute>
				<xsl:attribute name="groupname"><xsl:value-of select="$groupname"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">	
						<xsl:attribute name="samplename"><xsl:value-of select="../@name"/></xsl:attribute>	
						<xsl:attribute name="mfiavg"><xsl:value-of select="@sampleavg"/></xsl:attribute>
						<xsl:attribute name="addr"><xsl:value-of select="../@addr"/></xsl:attribute>
						<xsl:attribute name="id"><xsl:value-of select="@id + 1"/></xsl:attribute>
						
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						
						<xsl:attribute name="mfi"><xsl:value-of select="@mfi"/></xsl:attribute>
						<xsl:attribute name="bkgvalue"><xsl:value-of select="../../BeadInfo[@id=$beadid]/@bkgvalue"/></xsl:attribute>
						<xsl:attribute name="concv"><xsl:value-of select="@concv"/></xsl:attribute>
						<xsl:attribute name="stdev"><xsl:value-of select="@resstddev"/></xsl:attribute>
						<xsl:attribute name="samplecv"><xsl:value-of select="@samplecv"/></xsl:attribute>
						
						<xsl:choose>
  						<xsl:when test="@constr = ''">
    						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:attribute name="conavg"><xsl:value-of select="@constr"/></xsl:attribute>
  						</xsl:otherwise>
					</xsl:choose>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="@outlierbs"/></xsl:attribute>
						<xsl:attribute name="dilution"><xsl:value-of select="../@dilution"/></xsl:attribute>
						<xsl:attribute name="count"><xsl:value-of select="@count"/></xsl:attribute>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:for-each>
	
		</xsl:variable>
		
	<Row>
        
        <Cell><Data ss:Type="String">SB</Data></Cell>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell"><xsl:variable name="well"><xsl:value-of select="@id"/></xsl:variable>
					  
					  	<xsl:value-of select="../../../Well[@wellid = $well]/@addr"/><xsl:text>,</xsl:text>
					  	</xsl:for-each> 
					  	</Data></Cell>
					  	
					
	
		<!-- Traverse through the unknowngroupdata variable -->
		<xsl:for-each select="msxsl:node-set($unknowngroupdata)/GrpWell">
			<xsl:variable name="grname"><xsl:value-of select="@groupname"/></xsl:variable>
			<xsl:variable name="num_reps"><xsl:value-of select="@num_reps"/></xsl:variable>
			<xsl:variable name="num_beads"><xsl:value-of select="count(GrpBead)"/></xsl:variable>
				<xsl:for-each select="GrpBead">
					<xsl:variable name="plexid"><xsl:value-of select="@id"/></xsl:variable>		
					<xsl:variable name="num_valid_beads"><xsl:value-of select="count(//GrpWell/GrpBead[@status = '1'][@id = $plexid])"/></xsl:variable>
					<xsl:if test="$plexid = 1">
					<!-- 	<xsl:value-of select="$grname"/><xsl:text>,</xsl:text>
						
					Grab Wells 
					
						<xsl:value-of select="@addr"/><xsl:text>,</xsl:text>--></xsl:if>
								<xsl:call-template name="stringtestcv"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>
        
					
				
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	
		</Table>
		</xsl:element>
		
	</xsl:for-each> 
	
	
	 <xsl:text disable-output-escaping="yes">&lt;/Workbook&gt;</xsl:text>
	<!--</Workbook> -->

</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:call-template name="RowName">
          <xsl:with-param name="name" select="$rowcounter" />
        </xsl:call-template>
        <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:param name="screen" />
		test<xsl:value-of select="$screen"/>
		<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:with-param name="screen" select="$screen"/>
				</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:with-param name="screen" select="$screen"/>
			</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:param name="screen" />
		<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:variable name="beadcount2">
								<xsl:value-of select="sum(/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]/Bead/@count)" />					
						</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="$beadcount2 &lt; $screen">
													<Cell ss:StyleID="count" ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>		
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$beadcount2 &lt; $screen">
													<Cell ss:StyleID="count" ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</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="$beadcount2 &lt; $screen">
													<Cell ss:StyleID="count" ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$beadcount2 &lt; $screen">
													<Cell ss:StyleID="count" ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</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="$beadcount2 &lt; $screen">
													<Cell ss:StyleID="count" ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:when>
										<!-- middle cells -->
										<xsl:otherwise>
											<xsl:choose>
												<xsl:when test="$beadcount2 &lt; $screen">
													<Cell ss:StyleID="count" ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</Data>
													</Cell>
												</xsl:when>
												<xsl:otherwise>
													<Cell ss:Index="{$columnID + $offset}" >
														<Data ss:Type="Number">
															<xsl:value-of select="$beadcount2" />
														</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="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:with-param name="screen" select="$screen"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

<xsl:template name="Scientific">
	<xsl:param name="Num"/>
	<xsl:choose>
	<xsl:when 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:when>
	<xsl:when 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:when>
	<xsl:when test="not(boolean(number(substring-after($Num,'E'))))">
		<xsl:value-of select='format-number($Num, "#.00")'/>
	</xsl:when>
	</xsl:choose>	
</xsl:template>
<xsl:template name="Scientific2">
	<xsl:param name="Num"/>
	<xsl:choose>
	<xsl:when 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:when>
	<xsl:when 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:when>
	<xsl:when test="not(boolean(number(substring-after($Num,'E'))))">
		<xsl:value-of select='format-number($Num, "#.")'/>
	</xsl:when>
	</xsl:choose>	
</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="calc_variance">
  <xsl:param name="nodes" />
  <xsl:param name="sum" />
  <xsl:param name="sum-sq" />
  <xsl:param name="count" />
  <xsl:param name="mcparam" />

  <xsl:choose>
    <xsl:when test="not($nodes)">
      <xsl:variable name="variancenum"><xsl:value-of select="($sum-sq - ($sum * $sum) div $count) div ($count - 1)"/></xsl:variable> 
	<!--<xsl:text>Variance=</xsl:text><xsl:value-of select="$variancenum" /><xsl:text>,</xsl:text>-->

	<xsl:call-template name="sqrt">	
		<xsl:with-param name="num" select="$variancenum"/>
		<xsl:with-param name="meanconcparam2" select="$mcparam"/>
	</xsl:call-template>

    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="value" select="$nodes[1]"/>
      <xsl:call-template name="calc_variance">
        <xsl:with-param name="nodes" select="$nodes[position( ) != 1]"/>
        <xsl:with-param name="sum" select="$sum + $value"/>
        <xsl:with-param name="sum-sq" select="$sum-sq + ($value * $value)"/>
        <xsl:with-param name="count" select="$count + 1"/>
	  <xsl:with-param name="mcparam" select="$mcparam"/>

      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="stringtest">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="starts-with($string, 'NaN')">
<Cell><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, 'Error')">
<Cell><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, 'Infinity')">
<Cell><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '-Infinity')">
<Cell><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&lt;')">
<Cell><Data ss:Type="String"><xsl:value-of select="$string" /></Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&gt;')">
<Cell><Data ss:Type="String"><xsl:value-of select="$string" /></Data></Cell>
</xsl:when>
<xsl:otherwise>
<Cell><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:template name="stringtestcount">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="starts-with($string, 'NaN')">
<Cell ss:StyleID="count"><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, 'Error')">
<Cell ss:StyleID="count"><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, 'Infinity')">
<Cell ss:StyleID="count"><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '-Infinity')">
<Cell ss:StyleID="count"><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&lt;')">
<Cell ss:StyleID="count"><Data ss:Type="String"><xsl:value-of select="$string" /></Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&gt;')">
<Cell ss:StyleID="count"><Data ss:Type="String"><xsl:value-of select="$string" /></Data></Cell>
</xsl:when>
<xsl:when test="$string = 0">
<Cell ss:StyleID="count"><Data ss:Type="Number"><xsl:value-of select="$string" /></Data></Cell>
</xsl:when>
<xsl:when test="$string &lt; 40">
<Cell ss:StyleID="count"><Data ss:Type="Number"><xsl:call-template name="Scientific2">
						<xsl:with-param name="Num" select="$string" />
					</xsl:call-template></Data></Cell>
</xsl:when>
<xsl:otherwise>
<Cell><Data ss:Type="Number"><xsl:call-template name="Scientific2">
						<xsl:with-param name="Num" select="$string" />
					</xsl:call-template></Data></Cell>
</xsl:otherwise>					
</xsl:choose>
</xsl:template>

<xsl:template name="stringtestcv">
<xsl:param name="string"/>
<xsl:choose>
	<xsl:when test="starts-with($string, 'NaN')">
		<Cell ><Data ss:Type="String">***</Data></Cell>
	</xsl:when>
	<xsl:when test="starts-with($string, 'Error')">
		<Cell ><Data ss:Type="String">***</Data></Cell>
	</xsl:when>
	<xsl:when test="starts-with($string, 'Infinity')">
		<Cell ><Data ss:Type="String">***</Data></Cell>
	</xsl:when>
	<xsl:when test="starts-with($string, '-Infinity')">
		<Cell ><Data ss:Type="String">***</Data></Cell>
	</xsl:when>
	<xsl:when test="starts-with($string, '&lt;')">
		<Cell ><Data ss:Type="String"><xsl:value-of select="$string" /></Data></Cell>
	</xsl:when>
	<xsl:when test="starts-with($string, '&gt;')">
		<Cell ><Data ss:Type="String"><xsl:value-of select="$string" /></Data></Cell>
	</xsl:when>
	<xsl:otherwise>
		<xsl:choose>
			<xsl:when test="$string &lt; 20">
				<Cell ss:StyleID="green"><Data ss:Type="Number"><xsl:call-template name="Scientific">
						<xsl:with-param name="Num" select="$string" />
					</xsl:call-template></Data></Cell>
			</xsl:when>
			<xsl:when test="$string &gt; 30">
				<Cell ss:StyleID="count"><Data ss:Type="Number"><xsl:call-template name="Scientific">
						<xsl:with-param name="Num" select="$string" />
					</xsl:call-template></Data></Cell>
			</xsl:when>
			<xsl:otherwise>
				<Cell><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:otherwise>					
</xsl:choose>
</xsl:template>

<xsl:template name="sqrt">
   <xsl:param name="num" select="0"/>  <!-- The number you want to find the square root of -->
   <xsl:param name="try" select="1"/>  <!-- The current 'try'.  This is used  internally. -->
   <xsl:param name="iter" select="1"/> <!-- The current iteration, checked against maxiter to limit loop count -->
   <xsl:param name="maxiter" select="10"/>  <!-- Set this up to insure  against infinite loops -->

   <!-- This template was written by Nate Austin using Sir Isaac Newton's
 method of finding roots -->

   <xsl:choose>
     <xsl:when test="$try * $try = $num or $iter &gt; $maxiter">
       <xsl:value-of select="$try"/>
     </xsl:when>
     <xsl:otherwise>
       <xsl:call-template name="sqrt">
         <xsl:with-param name="num" select="$num"/>
         <xsl:with-param name="try" select="$try - (($try * $try - $num) div (2 * $try))"/>
         <xsl:with-param name="iter" select="$iter + 1"/>
         <xsl:with-param name="maxiter" select="$maxiter"/>
       </xsl:call-template>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>


</xsl:stylesheet>
<!-- Hitachi Software Engineering America, Ltd -->
<!-- MiraiBio Group  (date) 10.3.2008          -->

