<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet id="PlateFormat 2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:exslt="http://exslt.org/common" version="1.0">
  <xsl:output method="xml" indent="yes" />
  <xsl:template match="/">
    <xsl:text disable-output-escaping="yes">&lt;Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"&gt;</xsl:text>
    <Styles>
      <Style ss:ID="s24">
        <Font x:Family="Swiss" ss:Bold="1" />
      </Style>
      <Style ss:ID="s10">
        <Font x:Family="Swiss" />
        <Interior ss:Color="#FF0000" ss:Pattern="Solid" />
      </Style>
      <Style ss:ID="s11">
        <Font x:Family="Swiss" />
        <Interior ss:Color="#FFFF00" ss:Pattern="Solid" />
      </Style>
      <Style ss:ID="s1">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s2">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s3">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s4">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s5">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s6">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s7">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s8">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s9">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0" />
      </Style>
      <Style ss:ID="s25">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s26">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s27">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s28">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s29">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s30">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s31">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s32">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
      <Style ss:ID="s33">
        <Borders>
          <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
          <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
        </Borders>
        <NumberFormat ss:Format="0.000" />
      </Style>
    </Styles>
    <xsl:for-each select="MasterPlexPlateData/BeadInfo">
      <xsl:variable name="AnalyteName">
        <xsl:value-of select="@beadname" />
      </xsl:variable>
      <xsl:variable name="background">
        <xsl:value-of select="@bkgvalue" />
      </xsl:variable>
      <xsl:variable name="BeadID">
        <xsl:value-of select="@id" />
      </xsl:variable>
      <xsl:element name="Worksheet">
        <xsl:attribute name="ss:Name">
          <xsl:value-of select="$AnalyteName" />
        </xsl:attribute>
        <xsl:variable name="numrows">
          <xsl:value-of select="/MasterPlexPlateData/Row" />
        </xsl:variable>
        <xsl:variable name="numcols">
          <xsl:value-of select="/MasterPlexPlateData/Col" />
        </xsl:variable>
        <Table>
        <Column ss:Index="1" ss:Width="125"/>
          <!-- Header information -->
          <Row>
            <Cell ss:Index="1" ss:StyleID="s24">
              <Data ss:Type="String">File Name</Data>
            </Cell>
            <Cell ss:Index="2">
              <Data ss:Type="String">
                <xsl:value-of select="/MasterPlexPlateData/FileName" />
              </Data>
            </Cell>
          </Row>
          <Row>
            <Cell ss:Index="1" ss:StyleID="s24">
              <Data ss:Type="String">Date</Data>
            </Cell>
            <Cell ss:Index="2">
              <Data ss:Type="String">
                <xsl:value-of select="/MasterPlexPlateData/RunDate" />
              </Data>
            </Cell>
            <Cell ss:Index="8" ss:StyleID="s24">
              <Data ss:Type="String">
              </Data>
            </Cell>
          </Row>
          <Row />
          <!-- end Header information -->
          <xsl:call-template name="PlateMap">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template>
          <xsl:call-template name="BeadCount">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template>
          <xsl:call-template name="Conc">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template>
         <xsl:call-template name="Mean_Conc">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template> 
          <xsl:call-template name="StdDev_Conc">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template> 
           <xsl:call-template name="CV_Conc">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template> 
          
          <xsl:call-template name="MFI">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template>
          <xsl:call-template name="MFI-Bkg">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
            <xsl:with-param name="bkg" select="$background" />
          </xsl:call-template>
          <xsl:call-template name="Mean_MFI">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template>
          
          <xsl:call-template name="StdDev">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template>
          <xsl:call-template name="CV">
            <xsl:with-param name="rowcounter" select="1" />
            <xsl:with-param name="maxrows" select="$numrows" />
            <xsl:with-param name="beadid" select="$BeadID" />
          </xsl:call-template>
          
        </Table>
        <xsl:variable name="colOffset">
          <xsl:value-of select="$numcols - 1" />
        </xsl:variable>
        <xsl:variable name="rowOffset">
          <xsl:value-of select="$numrows - 1" />
        </xsl:variable>
        <xsl:variable name="colStart">
          <xsl:value-of select="3" />
        </xsl:variable>
        <xsl:variable name="colEnd">
          <xsl:value-of select="$colOffset + $colStart" />
        </xsl:variable>
        <xsl:variable name="sectionjump">
          <xsl:value-of select="2" />
        </xsl:variable>
        <xsl:variable name="plateRowStart">
          <xsl:value-of select="7" />
        </xsl:variable>
        <xsl:variable name="plateRowEnd">
          <xsl:value-of select="$plateRowStart + $rowOffset" />
        </xsl:variable>
        <xsl:variable name="bcRowStart">
          <xsl:value-of select="$plateRowEnd + $sectionjump" />
        </xsl:variable>
        <xsl:variable name="bcRowEnd">
          <xsl:value-of select="$bcRowStart + $rowOffset" />
        </xsl:variable>
        <xsl:variable name="mfiRowStart">
          <xsl:value-of select="$bcRowEnd + $sectionjump" />
        </xsl:variable>
        <xsl:variable name="mfiRowEnd">
          <xsl:value-of select="$mfiRowStart + $rowOffset" />
        </xsl:variable>
        <xsl:variable name="avgbkgRowStart">
          <xsl:value-of select="$mfiRowEnd + $sectionjump" />
        </xsl:variable>
        <xsl:variable name="avgbkgRowEnd">
          <xsl:value-of select="$avgbkgRowStart + $rowOffset" />
        </xsl:variable>
        <xsl:variable name="signalRowStart">
          <xsl:value-of select="$avgbkgRowEnd + $sectionjump" />
        </xsl:variable>
        <xsl:variable name="signalRowEnd">
          <xsl:value-of select="$signalRowStart + $rowOffset" />
        </xsl:variable>
        <xsl:variable name="stddevRowStart">
          <xsl:value-of select="$signalRowEnd + $sectionjump" />
        </xsl:variable>
        <xsl:variable name="stddevRowEnd">
          <xsl:value-of select="$stddevRowStart + $rowOffset" />
        </xsl:variable>
        <xsl:variable name="cvRowStart">
          <xsl:value-of select="$stddevRowEnd + $sectionjump" />
        </xsl:variable>
        <xsl:variable name="cvRowEnd">
          <xsl:value-of select="$cvRowStart + $rowOffset" />
        </xsl:variable>
        <xsl:variable name="normRowStart">
          <xsl:value-of select="$cvRowEnd + $sectionjump" />
        </xsl:variable>
        <xsl:variable name="normRowEnd">
          <xsl:value-of select="$normRowStart + $rowOffset" />
        </xsl:variable>
      </xsl:element>
    </xsl:for-each>
    <xsl:text disable-output-escaping="yes">&lt;/Workbook&gt;</xsl:text>
  </xsl:template>
  <xsl:template name="header_cols">
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <Cell ss:Index="{$colcounter + 2}" ss:StyleID="s24">
        <Data ss:Type="Number">
          <xsl:value-of select="$colcounter" />
        </Data>
      </Cell>
      <xsl:call-template name="header_cols">
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="PlateMap">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">Plate Map</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="PlateMap_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="PlateMap">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="BeadCount">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">Bead Count</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="BeadCount_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="BeadCount">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="MFI">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">MFI</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="MFI_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="MFI">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="MFI-Bkg">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:param name="bkg" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">MFI-Bkg</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="MFI-Bkg_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
          <xsl:with-param name="bkg" select="$bkg" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="MFI-Bkg">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
        <xsl:with-param name="bkg" select="$bkg" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="Mean_MFI">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">Mean MFI</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="Mean_MFI_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="Mean_MFI">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="Conc">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">Concentration</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="Conc_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="Conc">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
   <xsl:template name="Mean_Conc">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">Mean Fold Concentration</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="Mean_Conc_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="Mean_Conc">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="StdDev_Conc">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">StdDev Mean Concentration</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="StdDev_Conc_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="StdDev_Conc">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
    <xsl:template name="CV_Conc">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">%CV Mean Concentration</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="CV_Conc_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="CV_Conc">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="StdDev">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">StdDev Mean MFI</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="StdDev_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="StdDev">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="CV">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="maxrows" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="start">
      <xsl:value-of select="$rowcounter - 1" />
    </xsl:variable>
    <xsl:variable name="columns">
      <xsl:value-of select="/MasterPlexPlateData/Col" />
    </xsl:variable>
    <xsl:if test="$start = '0'">
      <Row>
        <xsl:call-template name="header_cols">
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
        </xsl:call-template>
      </Row>
    </xsl:if>
    <xsl:if test="$rowcounter &lt; $maxrows + 1">
      <Row>
        <xsl:variable name="character">
          <xsl:value-of select="$rowcounter + 64" />
        </xsl:variable>
        <xsl:if test="$rowcounter = '1'">
          <Cell ss:Index="1">
            <Data ss:Type="String">%CV Mean MFI</Data>
          </Cell>
        </xsl:if>
        <Cell ss:Index="2" ss:Formula="=CHAR({$character})">
          <Data ss:Type="String" />
        </Cell>
        <xsl:call-template name="CV_Row">
          <xsl:with-param name="rowcounter" select="$rowcounter" />
          <xsl:with-param name="colcounter" select="1" />
          <xsl:with-param name="maxcols" select="$columns" />
          <xsl:with-param name="beadid" select="$beadid" />
        </xsl:call-template>
      </Row>
      <xsl:call-template name="CV">
        <xsl:with-param name="rowcounter" select="$rowcounter + 1" />
        <xsl:with-param name="maxrows" select="$maxrows" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
 
  <xsl:template name="PlateMap_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:choose>
              <xsl:when test="$rowcounter = '1'">
                <xsl:choose>
                  <!-- first cell -->
                  <xsl:when test="$colcounter = '1'">
                    <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s1">
                      <Data ss:Type="String">
                        <xsl:value-of select="@name" />
                      </Data>
                    </Cell>
                  </xsl:when>
                  <!-- middle cells -->
                  <xsl:otherwise>
                    <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s2">
                      <Data ss:Type="String">
                        <xsl:value-of select="@name" />
                      </Data>
                    </Cell>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <xsl:when test="$rowcounter = $numrows">
                <xsl:choose>
                  <!-- first cell -->
                  <xsl:when test="$colcounter = '1'">
                    <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s7">
                      <Data ss:Type="String">
                        <xsl:value-of select="@name" />
                      </Data>
                    </Cell>
                  </xsl:when>
                  <!-- middle cells -->
                  <xsl:otherwise>
                    <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s8">
                      <Data ss:Type="String">
                        <xsl:value-of select="@name" />
                      </Data>
                    </Cell>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:when>
              <xsl:otherwise>
                <xsl:choose>
                  <!-- first cell -->
                  <xsl:when test="$colcounter = '1'">
                    <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s4">
                      <Data ss:Type="String">
                        <xsl:value-of select="@name" />
                      </Data>
                    </Cell>
                  </xsl:when>
                  <!-- middle cells -->
                  <xsl:otherwise>
                    <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s5">
                      <Data ss:Type="String">
                        <xsl:value-of select="@name" />
                      </Data>
                    </Cell>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s3">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s2">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s9">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s8">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s6">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s5">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="PlateMap_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="BeadCount_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s1">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@count" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s2">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@count" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s7">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@count" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s8">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@count" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s4">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@count" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s5">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@count" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s3">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s2">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s9">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s8">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s6">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s5">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="BeadCount_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="MFI_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="MFI_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="MFI-Bkg_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:param name="bkg" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi - $bkg" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi - $bkg" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi - $bkg" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi - $bkg" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi - $bkg" />
                        </Data>
                      </Cell>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                        <Data ss:Type="Number">
                          <xsl:value-of select="@mfi - $bkg" />
                        </Data>
                      </Cell>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="MFI-Bkg_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
        <xsl:with-param name="bkg" select="$bkg" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="Mean_MFI_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@sampleavg = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@sampleavg = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@sampleavg" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@sampleavg = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@sampleavg = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@sampleavg" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@sampleavg = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@sampleavg = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@sampleavg" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@sampleavg = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@sampleavg = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@sampleavg" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@sampleavg = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@sampleavg = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@sampleavg" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@sampleavg = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@sampleavg = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@sampleavg" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="Mean_MFI_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="Conc_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:variable name="bkgavg">
        <xsl:value-of select="/MasterPlexPlateData/BeadInfo[@id=$beadid]/@bkgvalue" />
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:variable name="sampleavg1">
                <xsl:call-template name="Scientific">
                  <xsl:with-param name="Num" select="@sampleavg" />
                </xsl:call-template>
              </xsl:variable>
              <xsl:variable name="result">
                <xsl:value-of select="@conc" />
              </xsl:variable>
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="Conc_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="Mean_Conc_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:variable name="bkgavg">
        <xsl:value-of select="/MasterPlexPlateData/BeadInfo[@id=$beadid]/@bkgvalue" />
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:variable name="sampleavg1">
                <xsl:call-template name="Scientific">
                  <xsl:with-param name="Num" select="@sampleavg" />
                </xsl:call-template>
              </xsl:variable>
              <xsl:variable name="result">
                <xsl:value-of select="@conavg" />
              </xsl:variable>
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="Mean_Conc_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="StdDev_Conc_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:variable name="bkgavg">
        <xsl:value-of select="/MasterPlexPlateData/BeadInfo[@id=$beadid]/@bkgvalue" />
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:variable name="sampleavg1">
                <xsl:call-template name="Scientific">
                  <xsl:with-param name="Num" select="@sampleavg" />
                </xsl:call-template>
              </xsl:variable>
              <xsl:variable name="result">
                <xsl:value-of select="@constddev" />
              </xsl:variable>
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="StdDev_Conc_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="CV_Conc_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:variable name="bkgavg">
        <xsl:value-of select="/MasterPlexPlateData/BeadInfo[@id=$beadid]/@bkgvalue" />
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:variable name="sampleavg1">
                <xsl:call-template name="Scientific">
                  <xsl:with-param name="Num" select="@sampleavg" />
                </xsl:call-template>
              </xsl:variable>
              <xsl:variable name="result">
                <xsl:value-of select="@concv * 100" />
              </xsl:variable>
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="$result = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="$result = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="$result" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="CV_Conc_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="StdDev_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@resstddev = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@resstddev = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@resstddev" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@resstddev = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@resstddev = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@resstddev" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@resstddev = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@resstddev = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@resstddev" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@resstddev = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@resstddev = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@resstddev" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@resstddev = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@resstddev = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@resstddev" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@resstddev = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@resstddev = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@resstddev" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="StdDev_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="CV_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@samplecv = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@samplecv = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@samplecv" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@samplecv = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@samplecv = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@samplecv" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@samplecv = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@samplecv = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@samplecv" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@samplecv = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@samplecv = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@samplecv" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@samplecv = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@samplecv = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@samplecv" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@samplecv = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@samplecv = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@samplecv" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="CV_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="Normalized_Row">
    <xsl:param name="rowcounter" select="1" />
    <xsl:param name="colcounter" select="1" />
    <xsl:param name="maxcols" select="1" />
    <xsl:param name="beadid" select="1" />
    <xsl:variable name="offset">
      <xsl:value-of select="2" />
    </xsl:variable>
    <xsl:variable name="numrows">
      <xsl:value-of select="/MasterPlexPlateData/Row" />
    </xsl:variable>
    <xsl:if test="$colcounter &lt; $maxcols + 1">
      <xsl:choose>
        <xsl:when test="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
          <xsl:for-each select="/MasterPlexPlateData/Well[@rowid=$rowcounter][@colid=$colcounter]">
            <xsl:variable name="columnID">
              <xsl:value-of select="@colid" />
            </xsl:variable>
            <xsl:for-each select="Bead[@id=$beadid]">
              <xsl:choose>
                <xsl:when test="$rowcounter = '1'">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@normalized = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@normalized = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s25">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@normalized" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@normalized = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@normalized = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s26">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@normalized" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:when test="$rowcounter = $numrows">
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@normalized = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@normalized = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s29">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@normalized" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@normalized = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@normalized = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s30">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@normalized" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:choose>
                    <!-- first cell -->
                    <xsl:when test="$colcounter = '1'">
                      <xsl:choose>
                        <xsl:when test="@normalized = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@normalized = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s28">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@normalized" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:when>
                    <!-- middle cells -->
                    <xsl:otherwise>
                      <xsl:choose>
                        <xsl:when test="@normalized = 'NaN'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">NaN</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:when test="@normalized = 'Infinity'">
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="String">Infinity</Data>
                          </Cell>
                        </xsl:when>
                        <xsl:otherwise>
                          <Cell ss:Index="{$columnID + $offset}" ss:StyleID="s33">
                            <Data ss:Type="Number">
                              <xsl:value-of select="@normalized" />
                            </Data>
                          </Cell>
                        </xsl:otherwise>
                      </xsl:choose>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$rowcounter = '1'">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s27">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s26">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$rowcounter = $numrows">
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s31">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s30">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
              <xsl:choose>
                <xsl:when test="$colcounter = $maxcols">
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s32">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:when>
                <xsl:otherwise>
                  <Cell ss:Index="{$colcounter + $offset}" ss:StyleID="s33">
                    <Data ss:Type="String">Empty</Data>
                  </Cell>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="Normalized_Row">
        <xsl:with-param name="rowcounter" select="$rowcounter" />
        <xsl:with-param name="colcounter" select="$colcounter + 1" />
        <xsl:with-param name="maxcols" select="$maxcols" />
        <xsl:with-param name="beadid" select="$beadid" />
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  <xsl:template name="Scientific">
    <xsl:param name="Num" />
    <xsl:if test="boolean(number(substring-after($Num,'E')))">
      <xsl:call-template name="Scientific_Helper">
        <xsl:with-param name="m" select="substring-before($Num,'E')" />
        <xsl:with-param name="e" select="substring-after($Num,'E')" />
      </xsl:call-template>
    </xsl:if>
    <xsl:if test="not(boolean(number(substring-after($Num,'E'))))">
      <xsl:value-of select="format-number($Num, &quot;#.00&quot;)" />
    </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, &quot;#.00&quot;)" />
      </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:stylesheet>
