<?xml version="1.0" encoding="windows-1250"?>
<xsl:stylesheet id="Bio-Plex Total Data Export" 

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"> -->
 <!-- Create New source xml with proper Standard groups -->
    <xsl:variable name="plate">
      <xsl:for-each select="MasterPlexPlateData">
        <xsl:variable name="StandardGroup">
          <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:variable name="beadid">
              <xsl:value-of select="../../../@id"/>
            </xsl:variable>
            <xsl:variable name="GroupWellID">
              <xsl:value-of select="@wellid"/>
            </xsl:variable>
            <xsl:variable name="recovery">
              <xsl:value-of select="../../../../Well[@wellid=$GroupWellID]/Bead[@id=$beadid]/@conc" />
            </xsl:variable>
            <xsl:element name="StandardGroup">
              <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:copy-of select="Row" />
        <xsl:copy-of select="Col" />
        <xsl:copy-of select="FileName" />
        <xsl:copy-of select="PlateName" />
        <xsl:copy-of select="PlateType" />
        <xsl:copy-of select="RunDate" />
        <xsl:copy-of select="RunTime" />
        <xsl:copy-of select="AnlyDate" />
        <xsl:copy-of select="AnlyTime" />
        <xsl:copy-of select="Operator" />
        <xsl:copy-of select="LXVERSION" />
        <xsl:copy-of select="LXHWSN" />
        <xsl:copy-of select="BeadInfo" />
        <xsl:copy-of select="Well" />
        <xsl:element name="StandardGroupList">
          <xsl:for-each select="msxsl:node-set($StandardGroup)">
            <xsl:copy-of select="/" />
          </xsl:for-each>
        </xsl:element>
        <xsl:copy-of select="ControlGroupList" />
        <xsl:copy-of select="UnknowGroupList" />
        <xsl:copy-of select="BkgGroupList" />
        <xsl:element name="RegressionGroupList" />
        <xsl:copy-of select="StdCurveImage" />
      </xsl:for-each>
    </xsl:variable>
    <!---->
    <!-- Calculate %Recovery for each standard replicate -->
    <xsl:variable name="precovery">
      <xsl:for-each select="msxsl:node-set($plate)/BeadInfo">
        <xsl:element name="bead">
          <xsl:attribute name="id">
            <xsl:value-of select="@beadname" />
          </xsl:attribute>
          <xsl:variable name="beadid">
            <xsl:value-of select="@id" />
          </xsl:variable>
          <xsl:for-each select="../StandardGroupList/StandardGroup">
            <xsl:element name="standardgroup">
              <xsl:attribute name="name">
                <xsl:value-of select="@name" />
              </xsl:attribute>
              <xsl:for-each select="GroupWell">
                <xsl:element name="Groupwell">
                  <xsl:variable name="groupwellid">
                    <xsl:value-of select="@id" />
                  </xsl:variable>
                  <xsl:attribute name="wellid">
                    <xsl:value-of select="@id" />
                  </xsl:attribute>
                  <xsl:variable name="expconc">
                    <xsl:value-of select="../../../BeadInfo[@id=$beadid]//StandardCurve/DataSeries/StdWell[@wellid=$groupwellid]/@stdconc" />
                  </xsl:variable>
                  <xsl:attribute name="expconc">
                    <xsl:value-of select="../../../BeadInfo[@id=$beadid]//StandardCurve/DataSeries/StdWell[@wellid=$groupwellid]/@stdconc" />
                  </xsl:attribute>
                  <xsl:variable name="conc">
                    <xsl:value-of select="../../../Well[@wellid=$groupwellid]/Bead[@id=$beadid]/@conc" />
                  </xsl:variable>
                  <xsl:variable name="outlier">
                    <xsl:value-of select="../../../Well[@wellid=$groupwellid]/Bead[@id=$beadid]/@outlierbs" />
                  </xsl:variable>
                  <xsl:attribute name="recovery">
                    <xsl:value-of select="($conc div $expconc) * 100" />
                  </xsl:attribute>
                  <xsl:attribute name="outlier">
                    <xsl:value-of select="$outlier" />
                  </xsl:attribute>
                </xsl:element>
              </xsl:for-each>
            </xsl:element>
          </xsl:for-each>
        </xsl:element>
      </xsl:for-each>
    </xsl:variable>
    <!---->
    <!-- Calculate Average %recovery for each standard replicate group -->
    <xsl:variable name="percrecov">
      <xsl:for-each select="msxsl:node-set($precovery)/bead">
        <xsl:element name="bead">
          <xsl:attribute name="id">
            <xsl:value-of select="@id" />
          </xsl:attribute>
          <xsl:for-each select="standardgroup">
            <xsl:element name="standardgroup">
              <xsl:attribute name="name">
                <xsl:value-of select="@name" />
              </xsl:attribute>
              <xsl:for-each select="Groupwell[1]">
                <xsl:attribute name="expconc">
                  <xsl:value-of select="@expconc" />
                </xsl:attribute>
              </xsl:for-each>
              <xsl:value-of select="sum(Groupwell[@outlier=0]/@recovery) div count(Groupwell[@outlier=0]/@recovery)" />
              <xsl:text></xsl:text>
            </xsl:element>
          </xsl:for-each>
        </xsl:element>
      </xsl:for-each>
    </xsl:variable>
    <!---->
    <!-- Test %CV for each Standard Point -->
    <xsl:variable name="LOQ">
      <xsl:for-each select="msxsl:node-set($percrecov)/bead">
        <xsl:element name="bead">
          <xsl:attribute name="id">
            <xsl:value-of select="@id" />
          </xsl:attribute>
          <xsl:for-each select="standardgroup">
            <xsl:variable name="value">
              <xsl:value-of select="." />
            </xsl:variable>
            <xsl:choose>
              <xsl:when test="$value &gt;= 70 and $value &lt;=130">
                <xsl:element name="standardgroup">
                  <xsl:attribute name="name">
                    <xsl:value-of select="@name" />
                  </xsl:attribute>
                  <xsl:attribute name="loq">
                    <xsl:value-of select="@expconc" />
                  </xsl:attribute>
                </xsl:element>
              </xsl:when>
            </xsl:choose>
          </xsl:for-each>
        </xsl:element>
      </xsl:for-each>
    </xsl:variable>
    <!---->
    <!-- Determine ULOQ and LLOQ values-->
    <xsl:variable name="LOQ2">
      <xsl:element name="LOQ" >
        <xsl:for-each select="msxsl:node-set($LOQ)/bead">
          <xsl:element name="BeadInfo" >
            <xsl:attribute name="beadname">
              <xsl:value-of select="@id" />
            </xsl:attribute>
            <xsl:element name="ULOQ" >
              <xsl:attribute name="value">
                <xsl:value-of select="standardgroup[1]/@loq" />
              </xsl:attribute>
            </xsl:element>
            <xsl:element name="LLOQ" >
              <xsl:attribute name="value">
                <xsl:value-of select="standardgroup[last()]/@loq" />
              </xsl:attribute>
            </xsl:element>
          </xsl:element>
        </xsl:for-each>
      </xsl:element>
    </xsl:variable>
    <!---->
    <!-- Final Export with LOQ section added
    <xsl:element name="MasterPlexPlateData">
      <xsl:for-each select="msxsl:node-set($plate)">
        <xsl:copy-of select="/" />
      </xsl:for-each>
      <xsl:for-each select="msxsl:node-set($LOQ2)">
        <xsl:copy-of select="/" />
      </xsl:for-each>
      
    </xsl:element> --> 
    <xsl:variable name="MasterPlexPlateData">
    <xsl:element name="MasterPlexPlateData">
      <xsl:for-each select="msxsl:node-set($plate)">
        <xsl:copy-of select="/" />
      </xsl:for-each>
      <xsl:for-each select="msxsl:node-set($LOQ2)">
        <xsl:copy-of select="/" />
      </xsl:for-each>
      
    </xsl:element> 
      
    </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="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s64">
   <Font x:Family="Swiss" ss:Bold="1"/>
  </Style>
 </Styles><!--<Workbook> -->
 <!--<xsl:for-each select="MasterPlexPlateData/BeadInfo">-->
  <xsl:for-each select="msxsl:node-set($MasterPlexPlateData)/MasterPlexPlateData/BeadInfo"> 
  	
  <xsl:variable name ="weight">
				<xsl:choose>
					<xsl:when test="StandardCurve/@useweight = 1">	
						<xsl:choose>
							<xsl:when test="StandardCurve/@weightmethod = 0">
								<xsl:value-of select="'1/Y^2'"/>
							</xsl:when>
							<xsl:when test="StandardCurve/@weightmethod = 1">
								<xsl:value-of select="'1/Y'"/>
							</xsl:when>
							<xsl:when test="StandardCurve/@weightmethod = 2">
								<xsl:value-of select="'1/X^2'"/>
							</xsl:when>
							<xsl:when test="StandardCurve/@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="StandardCurve/@equationname = 'Five Parameter Logistics'">	
						<xsl:value-of select="'5PL'"/>
					</xsl:when>	
					<xsl:when test="StandardCurve/@equationname = 'Four Parameter Logistics'">	
						<xsl:value-of select="'4PL'"/>
					</xsl:when>
					<xsl:otherwise><xsl:value-of select="StandardCurve/@equationname"/></xsl:otherwise>	
				</xsl:choose></xsl:variable>
				
					<xsl:variable name ="r2">	<xsl:value-of select="StandardCurve/@rsquare"/></xsl:variable>
				
		<xsl:variable name ="a">	<xsl:value-of select="StandardCurve/Parameter[@paraid = 0]/@value"/></xsl:variable>
		<xsl:variable name ="b">	<xsl:value-of select="StandardCurve/Parameter[@paraid = 1]/@value"/></xsl:variable>
		<xsl:variable name ="c">	<xsl:value-of select="StandardCurve/Parameter[@paraid = 2]/@value"/></xsl:variable>
		<xsl:variable name ="d">	<xsl:value-of select="StandardCurve/Parameter[@paraid = 3]/@value"/></xsl:variable>
		<xsl:variable name ="e">	<xsl:value-of select="StandardCurve/Parameter[@paraid = 4]/@value"/></xsl:variable>
			
			
			<xsl:variable name="quote">
          <xsl:text disable-output-escaping="yes">quot;</xsl:text>
          </xsl:variable>
          <xsl:variable name="amp">
          <xsl:text disable-output-escaping="yes">amp;</xsl:text>
          </xsl:variable>
			
			
				
				<xsl:variable name="AnalyteName"><xsl:value-of select="@beadname"/></xsl:variable> 
				<xsl:variable name="BeadNumber"><xsl:value-of select="@id"/></xsl:variable> 
				<xsl:variable name="bkgvalue"><xsl:value-of select="@bkgvalue"/></xsl:variable> 
				<xsl:variable name ="ULOQ">
					<xsl:value-of select="../LOQ/BeadInfo[@beadname = $AnalyteName]/ULOQ/@value"/>
  				</xsl:variable>
  				<xsl:variable name ="LLOQ">
  					<xsl:value-of select="../LOQ/BeadInfo[@beadname = $AnalyteName]/LLOQ/@value"/>
  				</xsl:variable>
		 
		<xsl:element name="Worksheet">
			 <xsl:attribute name="ss:Name"><xsl:value-of select="$AnalyteName"/></xsl:attribute>
			  <xsl:apply-templates /> 
		 <Table>
		 <Row>
		    <Cell ss:StyleID="s64"><Data ss:Type="String">File Name: <xsl:value-of select="../FileName"/></Data></Cell>
		   </Row>
       <Row>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Analyte: <xsl:value-of select="$AnalyteName"/></Data></Cell>
        </Row>
        <Row>
        
     <xsl:text disable-output-escaping="yes">&lt;Cell ss:StyleID="s64" ss:Formula="= &amp;</xsl:text><xsl:value-of select="$quote" /><xsl:text disable-output-escaping="yes">Acquisition Date: &amp;</xsl:text><xsl:value-of select="$quote" /><xsl:text disable-output-escaping="yes"> &amp;</xsl:text><xsl:value-of select="$amp" /><xsl:text disable-output-escaping="yes"> TEXT(RC[6],&amp;</xsl:text><xsl:value-of select="$quote" /><xsl:text disable-output-escaping="yes">dd-mmm-yyyy hh:mm:ss&amp;</xsl:text><xsl:value-of select="$quote" /><xsl:text disable-output-escaping="yes">)"&gt;</xsl:text><Data ss:Type="String"></Data><xsl:text disable-output-escaping="yes">&lt;/Cell&gt;</xsl:text>
      <Cell ss:Index="7"><Data ss:Type="String"><xsl:value-of select="../RunDate"/><xsl:text> </xsl:text><xsl:value-of select="../RunTime"/></Data></Cell>
      
        
        </Row>
        <Row>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Reader Serial Number: <xsl:value-of select="../LXHWSN"/></Data></Cell>
        </Row>
        <Row>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Plate ID: <xsl:value-of select="../PlateName"/></Data></Cell>
        </Row>
        <Row>
        <Cell ss:StyleID="s64"><Data ss:Type="String">RP1 PMT (Volts):</Data></Cell>
        <Cell ss:Index = "11" ss:StyleID="s64"><Data ss:Type="String">ULOQ</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">LLOQ</Data></Cell>
        </Row>
        <Row>
        <Cell ss:StyleID="s64"><Data ss:Type="String">RP1 Target:</Data></Cell>
        <Cell ss:Index = "11" ss:StyleID="s64"><Data ss:Type="Number"><xsl:value-of select="$ULOQ"/></Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="Number"><xsl:value-of select="$LLOQ"/></Data></Cell>
        </Row>
	         <Row />
	        <Row>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Analyte</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Type</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Well</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Outlier</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Description</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">FI</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">FI - Bkgd</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Std Dev</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Std Err</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">%CV</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc Std Dev</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc Std Err</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc %CV</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Exp Conc</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">(Obs/Exp) * 100</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Conc in Range</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Group</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Ratio</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Dilution</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Bead Count</Data></Cell>
      
     
        </Row>
	
	
	



	<!-- 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">	
	<!-- Outlier Status -->	
		<xsl:variable name="num_reps"><xsl:value-of select="count(GroupWell)" /></xsl:variable>
		
		<xsl:variable name="countthis">
              <xsl:for-each select="GroupWell">
              	
                <xsl:variable name="GroupWellID">
                  <xsl:value-of select="@id"/>
                </xsl:variable>
                <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
                  <xsl:choose>
                    <xsl:when test="@outlierbs=0">
                      <xsl:element name="n">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="id">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:element name="o">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="ido">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="n">
              <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
            </xsl:variable>
             <xsl:variable name="outlierstatus"> 
         	 <xsl:choose>
                    <xsl:when test="$n = 0">
                    	<xsl:value-of select="1" />
                    </xsl:when>	
                    <xsl:when test="$n = $num_reps">
                    	<xsl:value-of select="0" />
                    </xsl:when>
                    <xsl:otherwise>
                    	<xsl:value-of select="2" />
                    </xsl:otherwise>
                  </xsl:choose>	
         </xsl:variable> 
       <!-- End outlier check --> 
       <!-- OOR check --> 
            <xsl:variable name="countthis2">
              <xsl:for-each select="GroupWell">
              	
                <xsl:variable name="GroupWellID">
                  <xsl:value-of select="@id"/>
                </xsl:variable>
                <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
                  <xsl:choose>
                    <xsl:when test="@conc = 'NaN'">
                      <xsl:element name="n">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="id">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:element name="o">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="ido">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:variable>
            
            
            <xsl:variable name="n2">
              <xsl:value-of select="count(msxsl:node-set($countthis2)/n)" />
            </xsl:variable>
        
         <xsl:variable name="oorstatus"> 
         	 <xsl:choose>
                    <xsl:when test="$n2 = 0">
                    	<xsl:value-of select="0" />
                    </xsl:when>	
                    <xsl:otherwise>
                    	<xsl:value-of select="1" />
                    </xsl:otherwise>
                  </xsl:choose>	
         </xsl:variable>    
        <!-- End OOR Check --> 
		
		<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[@id=$BeadNumber]">
					<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:choose>
  							 	<xsl:when test="@conc = 'NaN'">
    								<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</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:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="$outlierstatus"/></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"><xsl:value-of select="$AnalyteName"/></Data></Cell>
        <Cell><Data ss:Type="String">B</Data></Cell>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell">
										<xsl:sort select="@id" data-type="number" order="ascending"/>
								<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>
							
					<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="@bkgvalue" /></xsl:call-template>
					<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="@stdev" /></xsl:call-template>		
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></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="String"></Data></Cell>	
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></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="@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>	
				<!--<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="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 Background Group -->
	
		<!-- Standard Group 1-->
	<xsl:for-each select="/MasterPlexPlateData/StandardGroupList/StandardGroup">

	
		<xsl:variable name="groupname">
  <xsl:value-of select="@name"/>
</xsl:variable>
<xsl:variable name="unknowngroupdata">
  <!-- Outlier Status -->
  <xsl:variable name="num_reps">
    <xsl:value-of select="count(GroupWell)" />
  </xsl:variable>
  <xsl:variable name="countthis">
    <xsl:for-each select="GroupWell">
      <xsl:variable name="GroupWellID">
        <xsl:value-of select="@id"/>
      </xsl:variable>
      <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
        <xsl:choose>
          <xsl:when test="@outlierbs=0">
            <xsl:element name="n">
            <!-- <xsl:value-of select="1" /> -->
              <xsl:attribute name="id">
                <xsl:value-of select="$GroupWellID" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <xsl:otherwise>
            <xsl:element name="o">
            <!--  <xsl:value-of select="1" /> -->
            
            <xsl:attribute name="id">
              <xsl:value-of select="$GroupWellID" />
            </xsl:attribute>
            </xsl:element>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="n">
    <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
  </xsl:variable>
  <xsl:variable name="outlierstatus">
    <xsl:choose>
      <xsl:when test="$n = 0">
        <xsl:value-of select="1" />
      </xsl:when>
      <xsl:when test="$n = $num_reps">
        <xsl:value-of select="0" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="2" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <xsl:variable name="outlierstatus2">
    <xsl:choose>
      <xsl:when test="$n = 0">
        <xsl:value-of select="1" />
      </xsl:when>
      <xsl:when test="$n = $num_reps">
        <xsl:value-of select="0" />
      </xsl:when>
      <xsl:when test="$n = 1">
        <xsl:value-of select="2" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="3" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <xsl:variable name="valid">
   <xsl:choose>
    <xsl:when test="$n &gt; 0">
     <xsl:value-of select="msxsl:node-set($countthis)/n[1]/@id" />
    </xsl:when>
    <xsl:otherwise>
    	<xsl:value-of select="msxsl:node-set($countthis)/o[1]/@id" />
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

        <!-- End Outlier Status --> 
               <!-- OOR check --> 
            <xsl:variable name="countthis2">
              <xsl:for-each select="GroupWell">
              	
                <xsl:variable name="GroupWellID">
                  <xsl:value-of select="@id"/>
                </xsl:variable>
                <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
                  <xsl:choose>
                    <xsl:when test="@conc = 'NaN'">
                      <xsl:element name="n">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="id">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:element name="o">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="ido">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:variable>
            
            
            <xsl:variable name="n2">
              <xsl:value-of select="count(msxsl:node-set($countthis2)/n)" />
            </xsl:variable>
        
         <xsl:variable name="oorstatus"> 
         	 <xsl:choose>
                    <xsl:when test="$n2 = 0">
                    	<xsl:value-of select="0" />
                    </xsl:when>	
                    <xsl:otherwise>
                    	<xsl:value-of select="1" />
                    </xsl:otherwise>
                  </xsl:choose>	
         </xsl:variable>    
        <!-- End OOR Check --> 
        
		<xsl:for-each select="GroupWell[@id = $valid]">
			

			<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[@id=$BeadNumber]">
					<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[@id=$BeadNumber]/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:attribute name="obsconc">		
					<xsl:choose>
  						<xsl:when test="@constr = ''">
  							<xsl:choose>
  							 	<xsl:when test="@conavg = 'NaN'">
    								<xsl:value-of select="@constr"/>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:value-of select="@conavg"/>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:value-of select="@constr"/>
  						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>	
						
						<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: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="$outlierstatus"/></xsl:attribute>
						<xsl:attribute name="outlier2"><xsl:value-of select="$outlierstatus2"/></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"><xsl:value-of select="$AnalyteName"/></Data></Cell>
        <Cell><Data ss:Type="String"><xsl:value-of select="$groupname"/></Data></Cell>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell">
										<xsl:sort select="@id" data-type="number" order="ascending"/>
										<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: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>
					
        	
					<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:choose>
						
						<xsl:when test="@outlier2 = 1"> <!-- All Outliers -->
							<!--MFI-->	<Cell><Data ss:Type="String">---</Data></Cell>
					<!--MFI - bkg-->	<Cell><Data ss:Type="String">---</Data></Cell>
					<!--Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell> 	
					<!--Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>		
						<!--%CV-->		<Cell><Data ss:Type="String"></Data></Cell>	
				
					<!--Conc Avg-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>			
					<!--Conc CV-->		<Cell><Data ss:Type="String"></Data></Cell>
					<!--Exp COnc-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@expconc" /></xsl:call-template>	
					<!--Rcovery-->		<Cell><Data ss:Type="String"></Data></Cell>	
			<!--Conc in Range-->		<Cell><Data ss:Type="String"></Data></Cell>
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:when>
						
						<xsl:when test="@outlier2 = 2"> <!-- One valid wells -->
							<!--MFI-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg + @bkgvalue" /></xsl:call-template>
					<!--MFI - bkg-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg" /></xsl:call-template>
					<!--Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>	 	
					<!--Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>		
						<!--%CV-->		<Cell><Data ss:Type="String"></Data></Cell>		
										
					<!--Conc Avg-->		<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				<!--Conc Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>			
					<!--Conc CV-->		<Cell><Data ss:Type="String"></Data></Cell>
					<!--Exp COnc-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@expconc" /></xsl:call-template>	
					<!--Rcovery-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="(@conavg div @expconc) * 100" /></xsl:call-template>	
			<!--Conc in Range-->		<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:when>		
						
						<xsl:otherwise> <!-- at least 1 failed but at at least 2 passed OR All passed -->
							<!--MFI-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg + @bkgvalue" /></xsl:call-template>
					<!--MFI - bkg-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg" /></xsl:call-template>
					<!--Std Dev-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 	
					<!--Std Err-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
						<!--%CV-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>	
					<!--Conc Avg-->		<xsl:call-template name="obsconc">
								<xsl:with-param name="string" select="@obsconc" />
								<xsl:with-param name="ULOQ" select="$ULOQ" />
								<xsl:with-param name="LLOQ" select="$LLOQ" />
							</xsl:call-template> 
				<!--Conc Std Dev-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
				<!--Conc Std Err-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>				
					<!--Conc CV-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<!--Exp COnc-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@expconc" /></xsl:call-template>	
					<!--Rcovery-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="(@conavg div @expconc) * 100" /></xsl:call-template>	
			<!--Conc in Range-->		<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:otherwise>
					</xsl:choose>	
					
	
				
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Standard Group -->	

	<!-- Controls -->
	
	<xsl:for-each select="/MasterPlexPlateData/ControlGroupList/ControlGroup">
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>
				<xsl:variable name="groupid"><xsl:value-of select="@groupid + 1"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<!-- Outlier Status -->	
		<xsl:variable name="num_reps"><xsl:value-of select="count(GroupWell)" /></xsl:variable>
		
		<xsl:variable name="countthis">
    <xsl:for-each select="GroupWell">
      <xsl:variable name="GroupWellID">
        <xsl:value-of select="@id"/>
      </xsl:variable>
      <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
        <xsl:choose>
          <xsl:when test="@outlierbs=0">
            <xsl:element name="n">
            <!-- <xsl:value-of select="1" /> -->
              <xsl:attribute name="id">
                <xsl:value-of select="$GroupWellID" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <xsl:otherwise>
            <xsl:element name="o">
            <!--  <xsl:value-of select="1" /> -->
            
            <xsl:attribute name="id">
              <xsl:value-of select="$GroupWellID" />
            </xsl:attribute>
            </xsl:element>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="n">
    <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
  </xsl:variable>
  <xsl:variable name="outlierstatus">
    <xsl:choose>
      <xsl:when test="$n = 0">
        <xsl:value-of select="1" />
      </xsl:when>
      <xsl:when test="$n = $num_reps">
        <xsl:value-of select="0" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="2" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="outlierstatus2">
    <xsl:choose>
      <xsl:when test="$n = 0">
        <xsl:value-of select="1" />
      </xsl:when>
      <xsl:when test="$n = $num_reps">
        <xsl:value-of select="0" />
      </xsl:when>
      <xsl:when test="$n = 1">
        <xsl:value-of select="2" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="3" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="valid">
   <xsl:choose>
    <xsl:when test="$n &gt; 0">
     <xsl:value-of select="msxsl:node-set($countthis)/n[1]/@id" />
    </xsl:when>
    <xsl:otherwise>
    	<xsl:value-of select="msxsl:node-set($countthis)/o[1]/@id" />
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

        <!-- End Outlier Status --> 
		<xsl:for-each select="GroupWell[@id = $valid]">
			

			<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:attribute name="groupid"><xsl:value-of select="$groupid"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]">
					<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:choose>
  							 	<xsl:when test="@conc = 'NaN'">
    								<xsl:attribute name="conc"><xsl:value-of select="@constr"/></xsl:attribute>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:attribute name="conc"><xsl:value-of select="@conc"/></xsl:attribute>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</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:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:attribute name="obsconc">		
					<xsl:choose>
  						<xsl:when test="@constr = ''">
  							<xsl:choose>
  							 	<xsl:when test="@conavg = 'NaN'">
    								<xsl:value-of select="@constr"/>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:value-of select="@conavg"/>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:value-of select="@constr"/>
  						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="$outlierstatus"/></xsl:attribute>
						<xsl:attribute name="outlier2"><xsl:value-of select="$outlierstatus2"/></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"><xsl:value-of select="$AnalyteName"/></Data></Cell>
        <Cell><Data ss:Type="String">C<xsl:value-of select="$groupid" /></Data></Cell>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell">
										<xsl:sort select="@id" data-type="number" order="ascending"/>
										<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>
					<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:choose>
						
						<xsl:when test="@outlier2 = 1"> <!-- All Outliers -->
							<!--MFI-->	<Cell><Data ss:Type="String">---</Data></Cell>
					<!--MFI - bkg-->	<Cell><Data ss:Type="String">---</Data></Cell>
					<!--Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell> 	
					<!--Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>		
						<!--%CV-->		<Cell><Data ss:Type="String"></Data></Cell>	
				
					<!--Conc Avg-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>			
					<!--Conc CV-->		<Cell><Data ss:Type="String"></Data></Cell>
					<!--Exp COnc-->		<Cell><Data ss:Type="String"></Data></Cell>		
					<!--Rcovery-->		<Cell><Data ss:Type="String"></Data></Cell>	
			<!--Conc in Range-->		<Cell><Data ss:Type="String"></Data></Cell>
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:when>
						
						<xsl:when test="@outlier2 = 2"> <!-- One valid wells -->
							<!--MFI-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg + @bkgvalue" /></xsl:call-template>
					<!--MFI - bkg-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg" /></xsl:call-template>
					<!--Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>	 	
					<!--Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>		
						<!--%CV-->		<Cell><Data ss:Type="String"></Data></Cell>		
						
					<!--Conc Avg-->		<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				<!--Conc Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>			
					<!--Conc CV-->		<Cell><Data ss:Type="String"></Data></Cell>
					<!--Exp COnc-->		<Cell><Data ss:Type="String"></Data></Cell>		
					<!--Rcovery-->		<Cell><Data ss:Type="String"></Data></Cell>		
			<!--Conc in Range-->		<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:when>
						<xsl:otherwise> <!-- at least 1 failed but at at least 2 passed OR All passed -->
							<!--MFI-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg + @bkgvalue" /></xsl:call-template>
					<!--MFI - bkg-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg" /></xsl:call-template>
					<!--Std Dev-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 	
					<!--Std Err-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
						<!--%CV-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>	
					
					<!--Conc Avg-->		<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				<!--Conc Std Dev-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
				<!--Conc Std Err-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>				
					<!--Conc CV-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<!--Exp COnc-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Rcovery-->		<Cell><Data ss:Type="String"></Data></Cell>		
			<!--Conc in Range-->		<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:otherwise>
					</xsl:choose>
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Controls -->
<!-- Start Unknown Replicates -->

	<xsl:for-each select="/MasterPlexPlateData/UnknowGroupList/UnknowGroup">
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>
				<xsl:variable name="groupid"><xsl:value-of select="@groupid + 1"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<!-- Outlier Status -->	
		<xsl:variable name="num_reps"><xsl:value-of select="count(GroupWell)" /></xsl:variable>
		
		<xsl:variable name="countthis">
    <xsl:for-each select="GroupWell">
      <xsl:variable name="GroupWellID">
        <xsl:value-of select="@id"/>
      </xsl:variable>
      <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
        <xsl:choose>
          <xsl:when test="@outlierbs=0">
            <xsl:element name="n">
            <!-- <xsl:value-of select="1" /> -->
              <xsl:attribute name="id">
                <xsl:value-of select="$GroupWellID" />
              </xsl:attribute>
            </xsl:element>
          </xsl:when>
          <xsl:otherwise>
            <xsl:element name="o">
            <!--  <xsl:value-of select="1" /> -->
            
            <xsl:attribute name="id">
              <xsl:value-of select="$GroupWellID" />
            </xsl:attribute>
            </xsl:element>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:for-each>
  </xsl:variable>
  <xsl:variable name="n">
    <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
  </xsl:variable>
  <xsl:variable name="outlierstatus">
    <xsl:choose>
      <xsl:when test="$n = 0">
        <xsl:value-of select="1" />
      </xsl:when>
      <xsl:when test="$n = $num_reps">
        <xsl:value-of select="0" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="2" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="outlierstatus2">
    <xsl:choose>
      <xsl:when test="$n = 0">
        <xsl:value-of select="1" />
      </xsl:when>
      <xsl:when test="$n = $num_reps">
        <xsl:value-of select="0" />
      </xsl:when>
      <xsl:when test="$n = 1">
        <xsl:value-of select="2" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="3" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="valid">
   <xsl:choose>
    <xsl:when test="$n &gt; 0">
     <xsl:value-of select="msxsl:node-set($countthis)/n[1]/@id" />
    </xsl:when>
    <xsl:otherwise>
    	<xsl:value-of select="msxsl:node-set($countthis)/o[1]/@id" />
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

        <!-- End Outlier Status --> 
		<xsl:for-each select="GroupWell[@id = $valid]">
			

			<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:attribute name="groupid"><xsl:value-of select="$groupid"/></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]">
					<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: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:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:attribute name="obsconc">		
					<xsl:choose>
  						<xsl:when test="@constr = ''">
  							<xsl:choose>
  							 	<xsl:when test="@conavg = 'NaN'">
    								<xsl:value-of select="@constr"/>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:value-of select="@conavg"/>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:value-of select="@constr"/>
  						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
						<xsl:attribute name="constddev"><xsl:value-of select="@constddev"/></xsl:attribute>
						<xsl:attribute name="outlier"><xsl:value-of select="$outlierstatus"/></xsl:attribute>
						<xsl:attribute name="outlier2"><xsl:value-of select="$outlierstatus2"/></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"><xsl:value-of select="$AnalyteName"/></Data></Cell>
        <Cell><Data ss:Type="String">X<xsl:value-of select="$groupid" /></Data></Cell>
		<Cell><Data ss:Type="String"><xsl:for-each select="GroupWell">
										<xsl:sort select="@id" data-type="number" order="ascending"/>
										<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>
						
					<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:choose>
						
						<xsl:when test="@outlier2 = 1"> <!-- All Outliers -->
							<!--MFI-->	<Cell><Data ss:Type="String">---</Data></Cell>
					<!--MFI - bkg-->	<Cell><Data ss:Type="String">---</Data></Cell>
					<!--Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell> 	
					<!--Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>		
						<!--%CV-->		<Cell><Data ss:Type="String"></Data></Cell>	
					
					<!--Conc Avg-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>			
					<!--Conc CV-->		<Cell><Data ss:Type="String"></Data></Cell>
					<!--Exp COnc-->		<Cell><Data ss:Type="String"></Data></Cell>		
					<!--Rcovery-->		<Cell><Data ss:Type="String"></Data></Cell>	
			<!--Conc in Range-->		<Cell><Data ss:Type="String"></Data></Cell>
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:when>
						
						<xsl:when test="@outlier2 = 2"> <!-- One valid wells -->
							<!--MFI-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg + @bkgvalue" /></xsl:call-template>
					<!--MFI - bkg-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg" /></xsl:call-template>
					<!--Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>	 	
					<!--Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>		
						<!--%CV-->		<Cell><Data ss:Type="String"></Data></Cell>		
					
					<!--Conc Avg-->		<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				<!--Conc Std Dev-->		<Cell><Data ss:Type="String"></Data></Cell>
				<!--Conc Std Err-->		<Cell><Data ss:Type="String"></Data></Cell>			
					<!--Conc CV-->		<Cell><Data ss:Type="String"></Data></Cell>
					<!--Exp COnc-->		<Cell><Data ss:Type="String"></Data></Cell>		
					<!--Rcovery-->		<Cell><Data ss:Type="String"></Data></Cell>		
			<!--Conc in Range-->		<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:when>
						<xsl:otherwise> <!-- at least 1 failed but at at least 2 passed OR All passed -->
							<!--MFI-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg + @bkgvalue" /></xsl:call-template>
					<!--MFI - bkg-->	<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfiavg" /></xsl:call-template>
					<!--Std Dev-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></xsl:call-template> 	
					<!--Std Err-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev div $num_reps" /></xsl:call-template>		
						<!--%CV-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@samplecv * 100" /></xsl:call-template>	
					
					<!--Conc Avg-->		<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				<!--Conc Std Dev-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></xsl:call-template>
				<!--Conc Std Err-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev div $num_reps" /></xsl:call-template>				
					<!--Conc CV-->		<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@concv * 100" /></xsl:call-template>
					<!--Exp COnc-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Rcovery-->		<Cell><Data ss:Type="String"></Data></Cell>		
			<!--Conc in Range-->		<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
						<!--N/A-->		<Cell><Data ss:Type="String"></Data></Cell>	
					<!--Dilution-->		<Cell><Data ss:Type="Number"><xsl:value-of select="@dilution"/></Data></Cell>
						</xsl:otherwise>
					</xsl:choose>
					
				</xsl:for-each>
			
		</xsl:for-each>
	</Row>
	</xsl:for-each>
	<!-- End Unknown Replicates -->
	
	<!-- Start Single Wells -->
<Row />	
<Row />
	        <Row>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Analyte</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Type</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Well</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Outlier</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Description</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">FI</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">FI - Bkgd</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Std Dev</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Std Err</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">%CV</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc Std Dev</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc Std Err</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Obs Conc %CV</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Exp Conc</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">(Obs/Exp) * 100</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Conc in Range</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Group</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Ratio</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Dilution</Data></Cell>
        <Cell ss:StyleID="s64"><Data ss:Type="String">Bead Count</Data></Cell>
        
     
        </Row>
	
	
	



	<!-- Background Group -->
	
	<xsl:for-each select="/MasterPlexPlateData/BkgGroupList/BkgGroup">
		
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<!-- Outlier Status -->	
		<xsl:variable name="num_reps"><xsl:value-of select="count(GroupWell)" /></xsl:variable>
		
		<xsl:variable name="countthis">
              <xsl:for-each select="GroupWell">
              	
                <xsl:variable name="GroupWellID">
                  <xsl:value-of select="@id"/>
                </xsl:variable>
                <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
                  <xsl:choose>
                    <xsl:when test="@outlierbs=0">
                      <xsl:element name="n">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="id">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:element name="o">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="ido">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="n">
              <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
            </xsl:variable>
         <xsl:variable name="outlierstatus"> 
         	 <xsl:choose>
                    <xsl:when test="$n = 0">
                    	<xsl:value-of select="1" />
                    </xsl:when>	
                    <xsl:when test="$n = $num_reps">
                    	<xsl:value-of select="0" />
                    </xsl:when>
                    <xsl:otherwise>
                    	<xsl:value-of select="2" />
                    </xsl:otherwise>
                  </xsl:choose>	
         </xsl:variable>    
        <!-- End Outlier Status --> 
		<xsl:for-each select="GroupWell">
			<xsl:sort select="@id" data-type="number" order="ascending"/>

			<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="../../../Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]">
					<xsl:variable name="beadid"><xsl:value-of select="@id"/></xsl:variable>
					<xsl:element name="GrpBead">
					<xsl:attribute name="obsconc">		
					<xsl:choose>
  						<xsl:when test="@constr = ''">
  							<xsl:choose>
  							 	<xsl:when test="@conc = 'NaN'">
    								<xsl:value-of select="@constr"/>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:value-of select="@conc"/>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:value-of select="@constr"/>
  						</xsl:otherwise>
					</xsl:choose>
				</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: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:attribute name="outlierstatus"><xsl:value-of select="$outlierstatus"/></xsl:attribute>
						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
						<xsl:attribute name="constdev"><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>
		
	
        
					  	
					
	
		<!-- 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: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>
		<Row>
        			<Cell><Data ss:Type="String"><xsl:value-of select="$AnalyteName"/></Data></Cell>
					<Cell><Data ss:Type="String">B</Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@addr"/></Data></Cell>	
					<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="@mfi" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfi" /></xsl:call-template>
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></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="@samplecv * 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="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:choose>
				<xsl:when test="@outlier = 0">
					<Cell><Data ss:Type="String"></Data></Cell>
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>	
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></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="@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>	
					<xsl:choose>
				<xsl:when test="@outlier = 0">
					<Cell><Data ss:Type="String"></Data></Cell>
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
					<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>
				</Row>		
				</xsl:for-each>
			
		</xsl:for-each>
	
	</xsl:for-each>
	
	<!-- End Background Group -->
	
	<!-- Standard Group 1-->
	  <!-- Create tree -->
	
	
	<xsl:for-each select="/MasterPlexPlateData/StandardGroupList/StandardGroup">
		<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<!-- Outlier Status -->	
		<xsl:variable name="num_reps"><xsl:value-of select="count(GroupWell)" /></xsl:variable>
		
		<xsl:variable name="countthis">
              <xsl:for-each select="GroupWell">
                <xsl:variable name="GroupWellID">
                  <xsl:value-of select="@id"/>
                </xsl:variable>
                <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
                  <xsl:choose>
                    <xsl:when test="@outlierbs=0">
                      <xsl:element name="n">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="id">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:element name="o">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="ido">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="n">
              <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
            </xsl:variable>
         <xsl:variable name="outlierstatus"> 
         	 <xsl:choose>
                    <xsl:when test="$n = 0">
                    	<xsl:value-of select="1" />
                    </xsl:when>	
                    <xsl:when test="$n = $num_reps">
                    	<xsl:value-of select="0" />
                    </xsl:when>
                    <xsl:otherwise>
                    	<xsl:value-of select="2" />
                    </xsl:otherwise>
                  </xsl:choose>	
         </xsl:variable>    
        <!-- End Outlier Status --> 
		<xsl:for-each select="GroupWell">
			<xsl:sort select="@id" data-type="number" order="ascending"/>

			<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[@id=$BeadNumber]">
					<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[@id=$BeadNumber]/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:attribute name="obsconc">		
					<xsl:choose>
  						<xsl:when test="@constr = ''">
  							<xsl:choose>
  							 	<xsl:when test="@conc = 'NaN'">
    								<xsl:value-of select="@constr"/>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:value-of select="@conc"/>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:value-of select="@constr"/>
  						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
						<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: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="outlierstatus"><xsl:value-of select="$outlierstatus"/></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>
		
	
        
					  	
					
	
		<!-- 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: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>
					
					<Row>
        			<Cell><Data ss:Type="String"><xsl:value-of select="$AnalyteName"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="$grname"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@addr"/></Data></Cell>	
					<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="@mfi" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfi - @bkgvalue" /></xsl:call-template>
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></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="@samplecv * 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="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:choose>
				<xsl:when test="@outlier = 0">
					<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
					<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="@expconc" /></xsl:call-template>	
				<xsl:choose>
				<xsl:when test="@outlier = 0">
						<xsl:call-template name="stringtest"><xsl:with-param name="string" select="(@conc div @expconc) * 100" /></xsl:call-template>	
				
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">***</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>	
					<xsl:choose>
				<xsl:when test="@outlier = 0">
					<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
					<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>
				</Row>			
				</xsl:for-each>
			
		</xsl:for-each>
	
	</xsl:for-each>
	<!-- End Standard Group -->	

	<!-- Controls -->
	
	<xsl:for-each select="/MasterPlexPlateData/ControlGroupList/ControlGroup">
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>	
				<xsl:variable name="groupid"><xsl:value-of select="@groupid + 1"/></xsl:variable>
		<xsl:variable name="unknowngroupdata">
		<!-- Outlier Status -->	
		<xsl:variable name="num_reps"><xsl:value-of select="count(GroupWell)" /></xsl:variable>
		
		<xsl:variable name="countthis">
              <xsl:for-each select="GroupWell">
                <xsl:variable name="GroupWellID">
                  <xsl:value-of select="@id"/>
                </xsl:variable>
                <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
                  <xsl:choose>
                    <xsl:when test="@outlierbs=0">
                      <xsl:element name="n">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="id">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:element name="o">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="ido">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="n">
              <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
            </xsl:variable>
         <xsl:variable name="outlierstatus"> 
         	 <xsl:choose>
                    <xsl:when test="$n = 0">
                    	<xsl:value-of select="1" />
                    </xsl:when>	
                    <xsl:when test="$n = $num_reps">
                    	<xsl:value-of select="0" />
                    </xsl:when>
                    <xsl:otherwise>
                    	<xsl:value-of select="2" />
                    </xsl:otherwise>
                  </xsl:choose>	
         </xsl:variable>    
        <!-- End Outlier Status --> 
		<xsl:for-each select="GroupWell">
			<xsl:sort select="@id" data-type="number" order="ascending"/>

			<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">C<xsl:value-of select="$groupid" /></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]">
					<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:attribute name="obsconc">		
					<xsl:choose>
  						<xsl:when test="@constr = ''">
  							<xsl:choose>
  							 	<xsl:when test="@conc = 'NaN'">
    								<xsl:value-of select="@constr"/>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:value-of select="@conc"/>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:value-of select="@constr"/>
  						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
						<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:attribute name="outlierstatus"><xsl:value-of select="$outlierstatus"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
						<xsl:attribute name="constdev"><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>
		

        
					  	
					
	
		<!-- 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: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>
					
					<Row>
        			<Cell><Data ss:Type="String"><xsl:value-of select="$AnalyteName"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="$grname"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@addr"/></Data></Cell>	
					<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="@mfi" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfi - @bkgvalue" /></xsl:call-template>
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></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="@samplecv * 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="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:choose>
				<xsl:when test="@outlier = 0">
					<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></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="@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>	
					<xsl:choose>
				<xsl:when test="@outlier = 0">
				<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
					<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>
				</Row>			
				</xsl:for-each>
			
		</xsl:for-each>
	
	</xsl:for-each>
	<!-- End Controls -->
<!-- Start Unknown -->

	<xsl:for-each select="/MasterPlexPlateData/UnknowGroupList/UnknowGroup">
				<xsl:variable name="groupname"><xsl:value-of select="@name"/></xsl:variable>
				<xsl:variable name="groupid"><xsl:value-of select="@groupid + 1"/></xsl:variable>	
		<xsl:variable name="unknowngroupdata">
		<!-- Outlier Status -->	
		<xsl:variable name="num_reps"><xsl:value-of select="count(GroupWell)" /></xsl:variable>
		
		<xsl:variable name="countthis">
              <xsl:for-each select="GroupWell">
                <xsl:variable name="GroupWellID">
                  <xsl:value-of select="@id"/>
                </xsl:variable>
                <xsl:for-each select="/MasterPlexPlateData/Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]" >
                  <xsl:choose>
                    <xsl:when test="@outlierbs=0">
                      <xsl:element name="n">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="id">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:element name="o">
                        <xsl:value-of select="1" />
                      </xsl:element>
                      <xsl:element name="ido">
                        <xsl:value-of select="$GroupWellID" />
                      </xsl:element>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:for-each>
              </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="n">
              <xsl:value-of select="count(msxsl:node-set($countthis)/n)" />
            </xsl:variable>
         <xsl:variable name="outlierstatus"> 
         	 <xsl:choose>
                    <xsl:when test="$n = 0">
                    	<xsl:value-of select="1" />
                    </xsl:when>	
                    <xsl:when test="$n = $num_reps">
                    	<xsl:value-of select="0" />
                    </xsl:when>
                    <xsl:otherwise>
                    	<xsl:value-of select="2" />
                    </xsl:otherwise>
                  </xsl:choose>	
         </xsl:variable>    
        <!-- End Outlier Status --> 
		<xsl:for-each select="GroupWell">
			<xsl:sort select="@id" data-type="number" order="ascending"/>

			<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">X<xsl:value-of select="$groupid" /></xsl:attribute>
				<xsl:for-each select="../../../Well[@wellid=$GroupWellID]/Bead[@id=$BeadNumber]">
					<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:attribute name="obsconc">		
					<xsl:choose>
  						<xsl:when test="@constr = ''">
  							<xsl:choose>
  							 	<xsl:when test="@conc = 'NaN'">
    								<xsl:value-of select="@constr"/>
    							</xsl:when>	
    							<xsl:otherwise>
    								<xsl:value-of select="@conc"/>
    							</xsl:otherwise>	
    						</xsl:choose>
  						</xsl:when>
  						<xsl:otherwise>
   				 			<xsl:value-of select="@constr"/>
  						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
						<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:attribute name="outlierstatus"><xsl:value-of select="$outlierstatus"/></xsl:attribute>
						<xsl:attribute name="constr"><xsl:value-of select="@constr"/></xsl:attribute>
						<xsl:attribute name="conavg"><xsl:value-of select="@conavg"/></xsl:attribute>
						<xsl:attribute name="constdev"><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>
		
	
        
					  	
					
	
		<!-- 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: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>
					
					
				<Row>
        			<Cell><Data ss:Type="String"><xsl:value-of select="$AnalyteName"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="$grname"/></Data></Cell>
					<Cell><Data ss:Type="String"><xsl:value-of select="@addr"/></Data></Cell>	
					<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="@mfi" /></xsl:call-template>
					<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@mfi - @bkgvalue" /></xsl:call-template>
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@stdev" /></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="@samplecv * 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="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:choose>
				<xsl:when test="@outlier = 0">
					<xsl:call-template name="obsconc">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template> 
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
				<!--<xsl:call-template name="stringtest"><xsl:with-param name="string" select="@constddev" /></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="@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>	
		<!-- Conc in Range-->		<xsl:choose>
				<xsl:when test="@outlier = 0">
					<xsl:call-template name="concinrange">
											<xsl:with-param name="string" select="@obsconc" />
											<xsl:with-param name="ULOQ" select="$ULOQ" />
											<xsl:with-param name="LLOQ" select="$LLOQ" />
										</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
						
				<xsl:choose>
					<xsl:when test="@outlierstatus = 1">	
						<Cell><Data ss:Type="String"></Data></Cell>
					</xsl:when>
					<xsl:when test="@outlierstatus = 2">
						<Cell><Data ss:Type="String">---</Data></Cell>
					</xsl:when>
					<xsl:otherwise>	
					</xsl:otherwise>
				</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
					<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>
				</Row>		
				</xsl:for-each>
			
		</xsl:for-each>
	
	</xsl:for-each>
	<!-- End Unknown  -->
	
	
	<Row />
					<Row>	<Cell><Data ss:Type="String">Sampling Errors: 1 - Low bead #, 2 - Agg beads, 3 - Classify %, 4 - Region selection, 5 - Platform temperature</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">***Value not available / --- = Designated as an outlier</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">*Value extrapolated beyond standard range</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">OOR = Out of Range / OOR&gt; = Out of Range Above  / OOR&lt; = Out of Range Below</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">Exp Conc = Expected Concentration  /  Obs Conc = Observed  Concentration</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">Conc in Range = Unknown sample concentrations within range where standards recovery is 70-130%</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">Ratio = Member/Reference</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">Regression Type: <xsl:value-of select="$equationname"/>; Weighting: <xsl:value-of select="$weight"/></Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">Std. Curve: ( <xsl:value-of select="$a"/> + ( <xsl:value-of select="$d"/> / (ABS((( 1 + ((x/(ABS(<xsl:value-of select="$c"/>))) ^ <xsl:value-of select="$b"/>)) ))^<xsl:value-of select="$e"/>) ) )</Data></Cell>	</Row>
					<Row>	<Cell><Data ss:Type="String">Rsquared <xsl:value-of select="$r2"/></Data></Cell>	</Row> 	
	</Table>
	</xsl:element>
			
	</xsl:for-each> 
	 <xsl:text disable-output-escaping="yes">&lt;/Workbook&gt;</xsl:text>
	<!--</Workbook> -->
<!--	</xsl:for-each> -->
</xsl:template>

<xsl:template name="Scientific">
  <xsl:param name="Num"/>
  <xsl:if test="boolean(number(substring-after($Num,'E')))">
    <xsl:call-template name="Scientific_Helper">
      <xsl:with-param name="m" select="substring-before($Num,'E')"/>
      <xsl:with-param name="e" select="substring-after($Num,'E')"/>
    </xsl:call-template>
  </xsl:if>
  <xsl:if test="not(boolean(number(substring-after($Num,'E'))))">
    <xsl:value-of select='format-number($Num, "#.00")'/>
  </xsl:if>
</xsl:template>
<xsl:template name="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, 'Infinity')">
<Cell><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&lt;')">
<Cell><Data ss:Type="String">OOR &lt;</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&gt;')">
<Cell><Data ss:Type="String">OOR &gt;</Data></Cell>
</xsl:when>
<xsl:when test="$string = ''">
<Cell><Data ss:Type="String">OOR &gt;</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="obsconc">
<xsl:param name="string"/>
<xsl:param name="ULOQ"/>
<xsl:param name="LLOQ"/>
<xsl:choose>
<xsl:when test="starts-with($string, 'NaN')">
<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">OOR &lt;</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&gt;')">
<Cell><Data ss:Type="String">OOR &gt;</Data></Cell>
</xsl:when>
<xsl:when test="$string = ''">
<Cell><Data ss:Type="String">OOR &gt;</Data></Cell>
</xsl:when>
<xsl:otherwise>
	<xsl:choose>
		<xsl:when test="$string &gt; $ULOQ">
			<Cell><Data ss:Type="String">*<xsl:call-template name="Scientific">
						<xsl:with-param name="Num" select="$string" />
					</xsl:call-template></Data></Cell>
		</xsl:when>	
		<xsl:when test="$string &lt; $LLOQ">
			<Cell><Data ss:Type="String">*<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="concinrange">
<xsl:param name="string"/>
<xsl:param name="ULOQ"/>
<xsl:param name="LLOQ"/>
<xsl:choose>
<xsl:when test="starts-with($string, 'NaN')">
<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">***</Data></Cell>
</xsl:when>
<xsl:when test="starts-with($string, '&gt;')">
<Cell><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:when test="$string = ''">
<Cell><Data ss:Type="String">***</Data></Cell>
</xsl:when>
<xsl:otherwise>
	<xsl:choose>
		<xsl:when test="$string &gt; $ULOQ">
			<Cell><Data ss:Type="String">***</Data></Cell>
		</xsl:when>	
		<xsl:when test="$string &lt; $LLOQ">
			<Cell><Data ss:Type="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: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          -->

