I've attached an XSLT stylesheet that we use to create a PDF version of
a clinical trial participant's lab report. It uses some fairly
complicated presentation logic that by necessity needs take place in the
last stage of processing. The FO output that it produces is also
somewhat involved, making use of many of the advanced features of
XSL:FO. The stylesheet represents about a man-month of work.

I sleep a lot better at night knowing that if for some reason FOP can't
meet my needs, there's a good chance I can switch over one of the
commercial FO->PDF processors without a major coding initiative. If
XSL:FO were prorietary to FOP, I would be living in fear of (1) having
to learn some new proprietary input format then (2) either weaving it
into this stylesheet or worse yet moving all this logic into some Java
class. 

In my opinion XSLT an extremely elegant presentation language. Java
seems clunky to me now. If you can manage your XML input so that it
represents the underlying structure of the data, you won't need to do
much processing at all in your stylesheet (ie - our levels are report,
study, doctor, patient, visit, test, analyte, etc.). For most of our
management reports the stylesheet is only a few templates and almost no
logic. XSLT/XPATH can be a little frustrating/intimidating when you're
first learning, especially if there's no one with experience nearby. I
have yet to find a good exhaustive XPATH reference. But it becomes more
straightforward once you learn all the shorthand. Like any good
language, after you learn a few pieces you can start guessing on the
syntax. 

We have a mirror of this stylesheet that outputs an HTML version of the
lab report. Yes it's a little bit of work to maintain both in parallel.
But I know if I really needed to (I.E. - we had 50 canned reports
instead of 6) I could come up with a system that factors out most of the
common presentation logic between HTML and FO. As far as I can see, if I
was using some straight XML->Java->PDF system like iText, I'd have to
either have my HTML generation in a JSP and my iText input creation in
some involved Java package, or try to create both outputs from some
really involved Java package. I don't think either system would be much
fun to mantain from a presentation POV. 

-Matt




Roland wrote:
> 
> At 12:59 PM 2/1/02 -0600, you wrote:
> 
> > > 2. XSLT is also kinda complicated to use, at least if you have to do
> > > complicated formatting...
> >So is any other kind of programming language.  The more complex the task,
> >the more lines of coded need to achieve the desired results.
> 
> Wrong! Look at iText http://www.lowagie.com/iText/ to see how simple their
> examples are. They build a complex table with just a few lines of java
> codes. Try doing the same with the XML/XSLT/XSL:FO approach and I guarantee
> you that the total outcome will be much more both in lines and complexity.
> I think to generate PDF with iText is as easy as generating XML from Java.
> XSLT is just a complicated language.
> 
> But I will take a closer look at our xsl files and see how and if things
> could be simplified...
> 
> Roland
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:fo="http://www.w3.org/1999/XSL/Format";>

 <xsl:param name="pdfImagePath" />
 
 <xsl:output method="xml"/>
 <xsl:preserve-space elements="*" />

 <xsl:key name="result-by-id" match="//QuickTrendResults/QuickTrendResult" use="./@ANALYTE_ID"/>
 <xsl:key name="analyte-by-id" match="//QuickTrend/QuickTrendTest/QuickTrendAnalyte" use="./@ANALYTE_ID"/>
 <xsl:key name="report-sequence" match="//QuickTrend" use="./@REPORT_SEQ"/>
 <xsl:key name="mod-five-list" match="//QuickTrend" use="@REPORT_SEQ mod 5"/>

 <xsl:variable name="print-results-demographics-every-page" select="/Report/@PRINT_DEM_EVERY_PAGE"/>
 <xsl:variable name="print-csr-demographics-every-page"     select="/Report/@CSR_DEM_EVERY_PAGE"/>
 <xsl:variable name="print-qt-qvh-demographics-every-page"  select="/Report/@QUICKTREND_DEM_EVERY_PAGE"/>
 <xsl:variable name="csr-show-demographics"                 select="/Report/@CSR_DEM_BLOCK"/>

 <xsl:variable name="show-demographics-on-right"            select="/Report/@DEM_RIGHT"/>
 <xsl:variable name="show-csr"                              select="/Report/@CSR_FLG"/>
 <xsl:variable name="csr-print-empty"                       select="/Report/@CSR_PRINT_EMPTY"/>
 <xsl:variable name="csr-finals-only"                       select="/Report/@CSR_FINALS_ONLY"/>
 <xsl:variable name="csr-print-if-storage"                  select="/Report/@CSR_PRINT_IF_STORAGE"/>
 <xsl:variable name="show-qt"                               select="/Report/@QUICKTREND_FLG"/>
 <xsl:variable name="qt-this-investigator"                  select="/Report/@QUICKTREND_THIS_INVTGR"/>
 <xsl:variable name="qt-this-visit"                         select="/Report/@QUICKTREND_THIS_VISIT"/>

 <xsl:variable name="quick-retest-flag"                     select="/Report/@QUICKRETEST_FLG"/>
 <xsl:variable name="show-qvh"                              select="/Report/@QVH_FLG"/>
 <xsl:variable name="qvh-this-visit"                        select="/Report/@QVH_THIS_VISIT"/>
 
 <xsl:variable name="report-status-code"                    select="/Report/@REPORT_STATUS_CODE"/>
 <xsl:variable name="report-date"                           select="/Report/@REPORT_DATE"/>
 <xsl:variable name="any-hold"                              select="/Report/@ANY_HOLD"/>
 <xsl:variable name="subheader-disclaimer-1"                select="/Report/@DISCLAIMER_1"/>   
 <xsl:variable name="temp-subheader-disclaimer"             select="/Report/@TEMP_DISCLAIMER"/>    
 <xsl:variable name="pending-subheader-disclaimer"          select="/Report/@PENDING_DISCLAIMER"/> 

 <xsl:template match="/">
  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format";>
   <xsl:apply-templates select="Report"/>
  </fo:root>
 </xsl:template>

 <xsl:template match="Report">

  <fo:layout-master-set>
    <fo:simple-page-master margin-right="1cm" margin-left="1cm" margin-bottom="1cm" margin-top="1cm" 
    		page-width="21.5cm" page-height="28cm" master-name="one">
     <fo:region-body margin-top="5.4cm" margin-bottom="1cm"/>
     <fo:region-before extent="5.4cm"/>
     <fo:region-after extent="1cm"/>
    </fo:simple-page-master>
   </fo:layout-master-set>

   <fo:page-sequence master-name="one">

    <fo:static-content flow-name="xsl-region-after">
     <fo:block text-align="end" font-weight="bold" font-size="8pt">Page: <fo:page-number/></fo:block>
    </fo:static-content>

    <fo:static-content flow-name="xsl-region-before">
     <fo:block text-align="center" font-size="10pt" font-weight="bold" color="#03845B">Laboratory Report</fo:block>
     <fo:block text-align="center" font-size="8pt" >
      <fo:table>
       <fo:table-column column-width="9.7cm"/>
       <fo:table-column column-width="2.4cm"/>
       <fo:table-column column-width="5cm"/>
       <fo:table-column column-width="2.3cm"/>
       <fo:table-body>
        <fo:table-row>
         <fo:table-cell>
          <fo:block text-align="start" space-before.optimum="6pt" space-after.optimum="0pt">
    
           <fo:table> 
           <fo:table-column column-width="9.7cm"/>
            <fo:table-body>
             <fo:table-row>
              <fo:table-cell padding-left="1pt" background-color="#BCE2D3" text-align="start" 
              	font-size="8pt" font-family="Courier"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid"
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-left-color="#03845B" border-left-width="0.5pt" border-left-style="solid">
                <fo:block>&#xA0;</fo:block>
               <xsl:if test="@ADDRESS_1='' or not(@ADDRESS_1)">
                <fo:block>&#xA0;</fo:block>
               </xsl:if>
               <xsl:if test="@ADDRESS_2='' or not(@ADDRESS_2)">
                <fo:block>&#xA0;</fo:block>
               </xsl:if>
               <fo:block font-weight="bold"><xsl:value-of select="@REPORT_NAME" /></fo:block>
               <fo:block><xsl:value-of select="@ADDRESS_1" /></fo:block>
               <fo:block><xsl:value-of select="@ADDRESS_2" /></fo:block>
               <fo:block><xsl:value-of select="@CITY" />, <xsl:value-of select="@STATE" />&#xA0;&#xA0;<xsl:value-of select="@ZIPCODE" /></fo:block>
               <fo:block><xsl:value-of select="@FOREIGN_ADDRESS" /></fo:block>
               <xsl:if test="@FOREIGN_ADDRESS='' or not(@FOREIGN_ADDRESS)">
                <fo:block>&#xA0;</fo:block>
               </xsl:if>
               <fo:block>&#xA0;</fo:block>
              </fo:table-cell>
             </fo:table-row>
            </fo:table-body>
           </fo:table>
       
          </fo:block>
         </fo:table-cell>
         <fo:table-cell />
         <fo:table-cell display-align="center">
          <fo:block space-before.optimum="5pt" space-after.optimum="0pt" display-align="center">

<!--
           <fo:external-graphic src="file:///usr/local/weblogic/config/isappdev/applications/RVWebApp1/WEB-INF/lib/ClinTrialLogoGreenBig.gif" />
           <fo:external-graphic src="http://localhost:7001/resultview/images/ClinTrialLogoGreenBig.gif"; />
-->
           <fo:external-graphic src="{concat($pdfImagePath,'ClinTrialLogoGreenBig.gif')}" />

          </fo:block>
         </fo:table-cell>
         <fo:table-cell />
        </fo:table-row>
        <fo:table-row padding-left="5pt">
         <fo:table-cell number-columns-spanned="4">
           <fo:block text-align="start">
    
           <fo:table background-color="#BCE2D3">
            <fo:table-column column-width="7cm"/>
            <fo:table-column column-width="7cm"/>
            <fo:table-column column-width="2.7cm"/>
            <fo:table-column column-width="2.7cm"/>
            <fo:table-body>
             <fo:table-row>
              <fo:table-cell padding-left="1pt" 
                border-left-color="#03845B" border-left-width="0.5pt" border-left-style="solid"
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid" 
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid">
               <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Patient Name</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@SUBJ_MNEM" /></fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="1pt"
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid">
               <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Patient ID</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@PATIENT_ID" /></fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="1pt"
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid">
               <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Age</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@AGE" /></fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="1pt"
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid">
                <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Sex</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@GENDER" /></fo:block>
              </fo:table-cell>
            </fo:table-row>
            </fo:table-body>
           </fo:table>
       
          </fo:block>
         </fo:table-cell>
        </fo:table-row>
  
        <fo:table-row padding-left="5pt">
         <fo:table-cell border-color="#03845B" border-width="0.5pt" border-style="solid" number-columns-spanned="4">
          <fo:block text-align="start">
    
           <fo:table background-color="#BCE2D3">
            <fo:table-column column-width="2.8cm"/>
            <fo:table-column column-width="3.4cm"/>
            <fo:table-column column-width="4.9cm"/>
            <fo:table-column column-width="3.4cm"/>
            <fo:table-column column-width="4.9cm"/>
            <fo:table-body>
             <fo:table-row>
              <fo:table-cell padding-left="1pt" 
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-left-color="#03845B" border-left-width="0.5pt" border-left-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid"
                border-bottom-color="#03845B" border-bottom-width="0.5pt" border-bottom-style="solid">
               <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Page</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><fo:page-number/> of <fo:page-number-citation ref-id="last-page"/></fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="1pt" 
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid"
                border-bottom-color="#03845B" border-bottom-width="0.5pt" border-bottom-style="solid">
               <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Requisition #</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@REQ_NUMBER" /></fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="1pt" 
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid"
                border-bottom-color="#03845B" border-bottom-width="0.5pt" border-bottom-style="solid">
               <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Collection Date &amp; Time         </fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@COLLECT_DATE" /></fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="1pt" 
                border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid"
                border-bottom-color="#03845B" border-bottom-width="0.5pt" border-bottom-style="solid">
                <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Login Date</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@RECEIPT_DATE" /></fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="1pt" 
              	border-right-color="#03845B" border-right-width="0.5pt" border-right-style="solid"
                border-top-color="#03845B" border-top-width="0.5pt" border-top-style="solid"
                border-bottom-color="#03845B" border-bottom-width="0.5pt" border-bottom-style="solid">
               <fo:block text-align="start" font-size="8pt" color="#03845B" font-weight="bold">Report Date &amp; Time</fo:block>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="@REPORT_DATE" /></fo:block>
              </fo:table-cell>
            </fo:table-row>
            </fo:table-body>
           </fo:table>
       
          </fo:block>
         </fo:table-cell>
        </fo:table-row>
 
        <fo:table-row>
         <fo:table-cell padding-left="1pt" number-columns-spanned="4">
          <fo:block text-align="start" space-before.optimum="3pt"  font-size="8pt" color="#03845B" font-weight="bold">Remarks:</fo:block>
         </fo:table-cell>
        </fo:table-row>

        <fo:table-row>
         <fo:table-cell padding-left="1pt" number-columns-spanned="4">
          <fo:block text-align="start" space-before.optimum="1pt"  font-family="Courier"  font-size="8pt" 
            font-weight="bold">&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<xsl:value-of select="@INVTGR_ACCT_NUMBER" />&#xA0;<xsl:value-of 
            select="@REQ_NUMBER" />&#xA0;<xsl:value-of select="@CHECK_DIGIT" /></fo:block>
         </fo:table-cell>
        </fo:table-row>

        <fo:table-row>
         <fo:table-cell padding-left="1pt" number-columns-spanned="4">
          <fo:block text-align="start" space-before.optimum="1pt"  font-family="Courier"  font-size="8pt" 
            font-weight="bold">&#xA0;<xsl:value-of select="@DUP_REMARK" />&#xA0;</fo:block>
         </fo:table-cell>
        </fo:table-row>

        <fo:table-row>
         <fo:table-cell padding-left="1pt" number-columns-spanned="4">
          <fo:block text-align="start" space-before.optimum="2pt"  space-after.optimum="3pt"  font-size="8pt" color="#03845B" 
            font-weight="bold">Report Status:<fo:inline font-family="Courier" color="black">&#xA0;&#xA0;<xsl:value-of select="@REPORT_STATUS" /></fo:inline></fo:block>
         </fo:table-cell>
        </fo:table-row>

       </fo:table-body>
      </fo:table>
     </fo:block>
    </fo:static-content>

    <fo:flow flow-name="xsl-region-body">

<!-- BEGIN RESULTS -->

     <fo:block text-align="center" space-after.optimum="0pt" space-before.optimum="0pt">    
      <fo:table>
        <xsl:if test="$print-results-demographics-every-page='N'">
         <xsl:attribute name="table-omit-header-at-break">true</xsl:attribute>
        </xsl:if>
       
       <fo:table-column column-width="19.4cm" 
           border-bottom-color="#03845B" border-bottom-width="2pt" border-bottom-style="solid" 
       		 border-right-color="#03845B" border-right-width="1pt" border-right-style="solid"
       		 border-left-color="#03845B" border-left-width="1pt" border-left-style="solid"/>

		<xsl:call-template name="demographic-subheader-block"/>

        <fo:table-body>

     <xsl:if test="Note[@NOTE_TYPE_ID='14']">
        <fo:table-row>
         <fo:table-cell background-color="#03845B" padding-left="1pt" number-columns-spanned="2">
          <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="1pt"  font-size="10pt" color="white" 
            font-weight="bold">Comments</fo:block>
         </fo:table-cell>
        </fo:table-row>

        <fo:table-row>
         <fo:table-cell background-color="white" number-columns-spanned="2" padding-left="4pt" >

       <xsl:apply-templates select="Note[@NOTE_TYPE_ID='14']" mode="report-comments"/>

         </fo:table-cell>
        </fo:table-row>
    </xsl:if>
 
        <fo:table-row>
         <fo:table-cell>
          <fo:block text-align="center" space-after.optimum="0pt" space-before.optimum="0pt">    
          
           <fo:table>
            <fo:table-column column-width="0.5cm"/>
            <fo:table-column column-width="5.3cm"/>
            <fo:table-column column-width="1.8cm"/>
            <fo:table-column column-width="2.2cm" background-color="#BCE2D3" />
            <fo:table-column column-width="2.2cm" background-color="#FFD5D9"/>
            <fo:table-column column-width="3.1cm"/>
            <fo:table-column column-width="3.5cm"/>
            <fo:table-column column-width="0.8cm"/>
          
			      <fo:table-footer>
             <fo:table-row font-family="Courier">
              <fo:table-cell number-columns-spanned="8"><fo:block font-size="4pt">&#xA0;</fo:block></fo:table-cell>
             </fo:table-row>
			      </fo:table-footer>
			      
			      <fo:table-header>
             <fo:table-row>
              <fo:table-cell background-color="#03845B" padding-left="1pt" number-columns-spanned="8">
               <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="1pt"  font-size="10pt" color="white" 
                 border-bottom-color="white" border-bottom-width="2pt" border-bottom-style="solid" 
                 font-weight="bold">Results</fo:block>
              </fo:table-cell>
             </fo:table-row>
          
             <fo:table-row background-color="#03845B"  text-align="start" font-size="8pt" color="white" font-weight="bold">
              <fo:table-cell number-columns-spanned="3">
               <fo:block space-before.optimum="1pt"  space-after.optimum="1pt"></fo:block>
              </fo:table-cell>
              <fo:table-cell number-columns-spanned="2">
               <fo:block space-before.optimum="1pt"  space-after.optimum="1pt" text-align="center" >Result</fo:block>
              </fo:table-cell>
              <fo:table-cell>
               <fo:block space-before.optimum="1pt"  space-after.optimum="1pt"></fo:block>
              </fo:table-cell>
              <fo:table-cell>
               <fo:block space-before.optimum="1pt"  space-after.optimum="1pt">Reference</fo:block>
              </fo:table-cell>
              <fo:table-cell>
               <fo:block space-before.optimum="1pt"  space-after.optimum="1pt">Site</fo:block>
              </fo:table-cell>
             </fo:table-row>
          
             <fo:table-row>
              <fo:table-cell number-columns-spanned="2"  background-color="#03845B" >
               <fo:block text-align="start" space-before.optimum="1pt"  space-after.optimum="1pt"  font-size="8pt" color="white" 
                 font-weight="bold">Test</fo:block>
              </fo:table-cell>
              <fo:table-cell  background-color="#03845B">
               <fo:block text-align="start" space-before.optimum="1pt"  space-after.optimum="1pt"  font-size="8pt" color="white" 
                 font-weight="bold">Flag</fo:block>
              </fo:table-cell>
              <fo:table-cell  background-color="#BCE2D3">
               <fo:block text-align="center" space-before.optimum="2pt"  space-after.optimum="1pt"  font-size="8pt" color="black"  
                 font-weight="bold">In Range</fo:block>
              </fo:table-cell>
              <fo:table-cell  background-color="#FFD5D9">
               <fo:block text-align="center" space-before.optimum="2pt"  space-after.optimum="1pt"  font-size="8pt" color="black"
                 font-weight="bold">Out of Range</fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="2pt"  background-color="#03845B">
               <fo:block text-align="start" space-before.optimum="1pt"  space-after.optimum="1pt"  font-size="8pt" color="white" 
                 font-weight="bold">Units</fo:block>
              </fo:table-cell>
              <fo:table-cell  background-color="#03845B">
               <fo:block text-align="start" space-before.optimum="1pt"  space-after.optimum="1pt"  font-size="8pt" color="white" 
                 font-weight="bold">Range</fo:block>
              </fo:table-cell>
              <fo:table-cell  background-color="#03845B">
               <fo:block text-align="start" space-before.optimum="1pt"  space-after.optimum="1pt"  font-size="8pt" color="white" 
                 font-weight="bold">Code</fo:block>
              </fo:table-cell>
             </fo:table-row>
          
             <fo:table-row>
              <fo:table-cell number-columns-spanned="3">
               <fo:block text-align="start" font-size="2pt">&#xA0;</fo:block>
              </fo:table-cell>
              <fo:table-cell background-color="#BCE2D3"/>
              <fo:table-cell background-color="#FFD5D9"/>
              <fo:table-cell number-columns-spanned="3"/>
             </fo:table-row>
            </fo:table-header>
          
            <fo:table-body>

     <xsl:apply-templates select="Test" mode="lab-report-results"/>

           <xsl:if test="Note[@NOTE_TYPE_ID='5']">

             <fo:table-row font-family="Courier" keep-with-next="always">
              <fo:table-cell number-columns-spanned="8"><fo:block font-size="12pt">&#xA0;</fo:block></fo:table-cell>
             </fo:table-row>

                 <xsl:apply-templates select="Note[@NOTE_TYPE_ID='5']" mode="report-footer" />
                 
             <fo:table-row font-family="Courier">
              <fo:table-cell number-columns-spanned="8"><fo:block font-size="4pt">&#xA0;</fo:block></fo:table-cell>
             </fo:table-row>
          </xsl:if>

            </fo:table-body>
           </fo:table>
          </fo:block>

         </fo:table-cell>
        </fo:table-row>
       </fo:table-body>
      </fo:table>
     </fo:block>


<!-- END RESULTS -->


   <xsl:if test="$show-csr='Y' 
                and ( $csr-print-if-storage='Y' or Test//Result[@ANALYTE_TYPE_CODE!='S'] ) 
                and ( $csr-finals-only='N' or ($report-status-code='F' or $report-status-code='A') )
                and ( Test//Result[@CSR_IND='Y' and @BLIND_IND='N'] or $csr-print-empty='Y' )">
    <!-- BEGIN CSR -->

    <xsl:call-template name="csr" />

    <!-- end CSR -->    

   </xsl:if>

 
  <xsl:if test="QuickTrend and $qt-this-visit='Y' and $qt-this-investigator='Y'">
   <!--  start Quick Trend/Retest -->   
		  
    <xsl:call-template name="quick-trend" />

   <!--  end Quick Trend -->
  </xsl:if>


  <xsl:if test="QuickViews/QuickView and $show-qvh='Y'">
   <!--  start Quick Visit History -->

     <xsl:call-template name="quick-visit-history" />  

   <!--  end Quick Visit History -->
  </xsl:if>

     <fo:block id="last-page"  space-after.optimum="10pt" space-before.optimum="10pt"
        text-align="center" font-size="10pt" font-weight="bold">END OF REPORT</fo:block>
    </fo:flow>
   </fo:page-sequence>
 </xsl:template>

 <xsl:template match="Test" mode="lab-report-results">

        <fo:table-row font-family="Courier">
         <fo:table-cell number-columns-spanned="3"><fo:block font-size="6pt">&#xA0;</fo:block></fo:table-cell>
         <fo:table-cell />
         <fo:table-cell />
         <fo:table-cell number-columns-spanned="3"/>
        </fo:table-row>
        
       
     <xsl:choose>
      <xsl:when test="@TEST_REPORT_TYPE_ID='0'">
       <xsl:apply-templates select="Result" mode="lab-report-results" />
      </xsl:when>
      <xsl:otherwise>
        <fo:table-row font-family="Courier">
         <fo:table-cell number-columns-spanned="3" padding-left="1pt">
           <fo:block text-align="start" font-size="8pt"
            font-weight="bold"><xsl:value-of select="@SERVICE_DESC" /></fo:block>
         </fo:table-cell>
         <fo:table-cell number-columns-spanned="5">
           <fo:block text-align="start" font-size="8pt"
            font-weight="bold"><xsl:value-of select="@TEST_REPORT_TYPE_DESC" /></fo:block>
         </fo:table-cell>
        </fo:table-row>

       <xsl:if test="(@TEST_REPORT_TYPE_ID='1' or @TEST_REPORT_TYPE_ID='2') and not(@TNP_CMT='')">
         <xsl:call-template name="generate-comments">
         	<xsl:with-param name="full-row-column-start" select="'1'"/>
          <xsl:with-param name="total-columns" select="'8'"/>
          <xsl:with-param name="result-column-start" select="'4'"/>
          <xsl:with-param name="comment-text" select="@TNP_CMT"/>
         </xsl:call-template>
       </xsl:if>

       </xsl:otherwise>
     </xsl:choose>

   <xsl:if test="not(@ORDER_CMT_TEXT='') or not(@REMARK_TEXT='') or not(@TSO_ADDRESS='')">
    <xsl:call-template name="test-comments">
    	<xsl:with-param name="full-row-column-start" select="'2'"/>
      <xsl:with-param name="total-columns" select="'8'"/>
      <xsl:with-param name="result-column-start" select="'4'"/>
    </xsl:call-template>
   </xsl:if>

 </xsl:template>

 <xsl:template name="generate-comments">
	<xsl:param name="comment-text" />
	<xsl:param name="result-column-start"/>
	<xsl:param name="full-row-column-start" />
	<xsl:param name="total-columns" />

     <xsl:choose>
      <xsl:when test="substring($comment-text, 1, 3) = '   '">
        <fo:table-row font-family="Courier">
         <fo:table-cell number-columns-spanned="{$full-row-column-start - 1}" />
         <fo:table-cell number-columns-spanned="{$total-columns - ($full-row-column-start - 1)}">
          <fo:block text-align="start" font-size="8pt" white-space-collapse="false">
           <xsl:call-template name="setNewLine">
            <xsl:with-param name="string" select="$comment-text"/>
           </xsl:call-template>
          </fo:block>
         </fo:table-cell>
        </fo:table-row>
      </xsl:when>
      <xsl:otherwise>
        <fo:table-row font-family="Courier">
         <fo:table-cell number-columns-spanned="{$result-column-start - 1}" />
         <fo:table-cell number-columns-spanned="{$total-columns - ($result-column-start - 1)}">
          <fo:block text-align="start" space-after.optimum="3pt" font-size="8pt" white-space-collapse="false">
           <xsl:call-template name="setNewLine">
            <xsl:with-param name="string" select="$comment-text"/>
           </xsl:call-template>
          </fo:block>
         </fo:table-cell>
        </fo:table-row>
      </xsl:otherwise>
     </xsl:choose>

 </xsl:template>

 <xsl:template match="Result" mode="lab-report-results">

      <xsl:variable name="result-column-start">
       <xsl:choose>
        <xsl:when test="@CLINICAL_STATUS_CODE='H' or @CLINICAL_STATUS_CODE='L' or @CLINICAL_STATUS_CODE='A'
              or @CLINICAL_STATUS_CODE='Z' or @CLINICAL_STATUS_CODE='I'">5</xsl:when>
        <xsl:otherwise>4</xsl:otherwise>
       </xsl:choose>
      </xsl:variable>

      <xsl:variable name="result-drops-row">
       <xsl:choose>
        <xsl:when test="(  ( ($result-column-start='5') and (string-length(@ALERT_FLAG) + string-length(@RSLT_VALUE)) &gt; 9 )
                         or( ($result-column-start='4') and (string-length(@ALERT_FLAG) + string-length(@RSLT_VALUE)) &gt; 18 )  
                        )">Y</xsl:when>
        <xsl:otherwise>N</xsl:otherwise>
       </xsl:choose>
      </xsl:variable>

      <xsl:if test="position()=1 and (count(../Result)!=1 or ../@SERVICE_DESC!=@ITEM_DESC)">
        <fo:table-row font-family="Courier">
         <fo:table-cell number-columns-spanned="3" padding-left="1pt">
           <fo:block text-align="start" font-size="8pt"
            font-weight="bold"><xsl:value-of select="../@SERVICE_DESC" />
            </fo:block>
         </fo:table-cell>
         <fo:table-cell />
         <fo:table-cell />
         <fo:table-cell number-columns-spanned="2"/>
         <fo:table-cell>
           <fo:block text-align="start" font-size="8pt"
            font-weight="bold"><xsl:value-of select="../@LAB_NAME" /></fo:block>
         </fo:table-cell>
        </fo:table-row>
      </xsl:if>

        <fo:table-row font-family="Courier">

     <xsl:choose>
      <xsl:when test="position()=1 and (count(../Result)=1 and ../@SERVICE_DESC=@ITEM_DESC)">
         <fo:table-cell number-columns-spanned="2" padding-left="1pt">
           <fo:block text-align="start" font-size="8pt"
            font-weight="bold"><xsl:value-of select="../@SERVICE_DESC" /></fo:block>
         </fo:table-cell>
      </xsl:when>
      <xsl:otherwise>
         <fo:table-cell />
         <fo:table-cell>
          <fo:block text-align="start" font-size="8pt">
           <xsl:value-of select="@ITEM_DESC" />
<!--
            $result-drops-row=<xsl:value-of select="$result-drops-row" />
            $result-column-start=<xsl:value-of select="$result-column-start" />
            (string-length(@ALERT_FLAG)=<xsl:value-of select="string-length(@ALERT_FLAG)" />
            (string-length(@RSLT_VALUE)=<xsl:value-of select="string-length(@RSLT_VALUE)" />
-->
           </fo:block>
         </fo:table-cell>
      </xsl:otherwise>
     </xsl:choose>

         <fo:table-cell>
          <fo:block text-align="start" font-size="8pt" color="red">

           <xsl:choose>
            <xsl:when test="@TOXICITY='' or not(@TOXICITY)">&#xA0;&#xA0;&#xA0;</xsl:when>
            <xsl:otherwise><xsl:value-of select="@TOXICITY" />&#xA0;</xsl:otherwise>
           </xsl:choose>

            <xsl:value-of select="@DELTA_IND" />

          </fo:block>
         </fo:table-cell>
         
     <xsl:choose>
      <xsl:when test="$result-drops-row='Y'">
 
          <xsl:choose>
           <xsl:when test="$result-column-start='5'">
              <fo:table-cell  />
              <fo:table-cell  padding-left="1pt" number-columns-spanned="3">
               <fo:block text-align="start" font-size="8pt">
               	<xsl:value-of select="@ALERT_FLAG" /><xsl:value-of select="@RSLT_VALUE" />
               </fo:block>
              </fo:table-cell>
           </xsl:when>
           <xsl:otherwise>
              <fo:table-cell padding-left="1pt" number-columns-spanned="4">
               <fo:block text-align="start" font-size="8pt">
               	<xsl:value-of select="@ALERT_FLAG" /><xsl:value-of select="@RSLT_VALUE" />
               </fo:block>
              </fo:table-cell>
           </xsl:otherwise>
          </xsl:choose>
         
      </xsl:when>
      <xsl:otherwise>

          <xsl:choose>
           <xsl:when test="$result-column-start='5'">
              <fo:table-cell  />
              <fo:table-cell  padding-left="1pt" >
               <fo:block text-align="start" font-size="8pt">
               	<xsl:value-of select="@ALERT_FLAG" /><xsl:value-of select="@RSLT_VALUE" />
               </fo:block>
              </fo:table-cell>
           </xsl:when>
           <xsl:otherwise>
              <fo:table-cell padding-left="1pt" number-columns-spanned="2">
               <fo:block text-align="start" font-size="8pt">
               	<xsl:value-of select="@ALERT_FLAG" /><xsl:value-of select="@RSLT_VALUE" />
               </fo:block>
              </fo:table-cell>
           </xsl:otherwise>
          </xsl:choose>
         
         <fo:table-cell padding-left="2pt">
          <fo:block text-align="start" font-size="8pt">
           <xsl:value-of select="@UOM_CODE" />
          </fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block text-align="start" font-size="8pt">
           <xsl:value-of select="@REF_RANGE_CMT" />
          </fo:block>
         </fo:table-cell>
         <fo:table-cell>

          <xsl:choose>
           <xsl:when test="position()=1 and (count(../Result)=1 and ../@SERVICE_DESC=@ITEM_DESC)">
                <fo:block text-align="start" font-size="8pt"
                 font-weight="bold"><xsl:value-of select="../@LAB_NAME" /></fo:block>
           </xsl:when>
           <xsl:otherwise>
               <fo:block text-align="start" font-size="8pt">
                <xsl:value-of select="@LAB_NAME" /></fo:block>
           </xsl:otherwise>
          </xsl:choose>
         </fo:table-cell>
          
      </xsl:otherwise>
     </xsl:choose>

        </fo:table-row>

  <xsl:if test="$result-drops-row='Y'">
        <fo:table-row font-family="Courier">
         <fo:table-cell number-columns-spanned="5" />
         <fo:table-cell padding-left="2pt">
          <fo:block text-align="start" font-size="8pt">
           <xsl:value-of select="@UOM_CODE" />
          </fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block text-align="start" font-size="8pt">
           <xsl:value-of select="@REF_RANGE_CMT" />
          </fo:block>
         </fo:table-cell>
         <fo:table-cell>

          <xsl:choose>
           <xsl:when test="position()=1 and (count(../Result)=1 and ../@SERVICE_DESC=@ITEM_DESC)">
                <fo:block text-align="start" font-size="8pt"
                 font-weight="bold"><xsl:value-of select="../@LAB_NAME" /></fo:block>
           </xsl:when>
           <xsl:otherwise>
               <fo:block text-align="start" font-size="8pt">
                <xsl:value-of select="@LAB_NAME" /></fo:block>
           </xsl:otherwise>
          </xsl:choose>
         </fo:table-cell>
        </fo:table-row>
  </xsl:if>

  <xsl:if test="( @RSLT_CORRECTED_IND='Y' or (@REF_RANGE_CMT2 and not(@REF_RANGE_CMT2='')) )">
        <fo:table-row font-family="Courier">
         <fo:table-cell number-columns-spanned="{$result-column-start - 1}"/>
         <fo:table-cell number-columns-spanned="{7 - $result-column-start}">
          <fo:block text-align="start" font-size="8pt">
           <xsl:if test="@RSLT_CORRECTED_IND='Y'">-- Amended Result --</xsl:if>             
          </fo:block>
         </fo:table-cell>
         <fo:table-cell text-align="start" font-size="8pt" number-columns-spanned="2">
          <fo:block><xsl:value-of select="@REF_RANGE_CMT2"/></fo:block>
         </fo:table-cell>
        </fo:table-row>
  </xsl:if>
  
  <xsl:if test="not(@RSLT_VALUE_CMT='') or not(@RSLT_REF_CMT='') or not(@REMARK_TEXT='')">
    <xsl:call-template name="result-comments">
    	<xsl:with-param name="full-row-column-start" select="'2'"/>
      <xsl:with-param name="total-columns" select="'8'"/>
      <xsl:with-param name="result-column-start" select="$result-column-start"/>
    </xsl:call-template>
  </xsl:if>
  
 </xsl:template>

 <xsl:template name="test-comments">
	<xsl:param name="result-column-start" />
	<xsl:param name="full-row-column-start" />
	<xsl:param name="total-columns" />

  <xsl:if test="not(@ORDER_CMT_TEXT='')">
    <xsl:call-template name="generate-comments">
      <xsl:with-param name="result-column-start" select="$result-column-start"/>
    	<xsl:with-param name="full-row-column-start" select="$full-row-column-start"/>
      <xsl:with-param name="total-columns" select="$total-columns"/>
      <xsl:with-param name="comment-text" select="@ORDER_CMT_TEXT"/>
    </xsl:call-template>
  </xsl:if>

  <xsl:if test="not(@REMARK_TEXT='')">
    <xsl:call-template name="generate-comments">
      <xsl:with-param name="result-column-start" select="$result-column-start"/>
    	<xsl:with-param name="full-row-column-start" select="$full-row-column-start"/>
      <xsl:with-param name="total-columns" select="$total-columns"/>
      <xsl:with-param name="comment-text" select="@REMARK_TEXT"/>
    </xsl:call-template>
  </xsl:if>
      
  <xsl:if test="not(@TSO_ADDRESS='')">
    <xsl:call-template name="generate-comments">
      <xsl:with-param name="result-column-start" select="$result-column-start"/>
    	<xsl:with-param name="full-row-column-start" select="$full-row-column-start"/>
      <xsl:with-param name="total-columns" select="$total-columns"/>
      <xsl:with-param name="comment-text" select="concat('TEST PERFORMED BY^', @TSO_ADDRESS)"/>
    </xsl:call-template>
  </xsl:if>
 </xsl:template>

 <xsl:template name="result-comments">
	<xsl:param name="result-column-start" />
	<xsl:param name="full-row-column-start" />
	<xsl:param name="total-columns" />

  <xsl:if test="not(@RSLT_VALUE_CMT='')">
    <xsl:call-template name="generate-comments">
      <xsl:with-param name="result-column-start" select="$result-column-start"/>
    	<xsl:with-param name="full-row-column-start" select="$full-row-column-start"/>
      <xsl:with-param name="total-columns" select="$total-columns"/>
      <xsl:with-param name="comment-text" select="@RSLT_VALUE_CMT"/>
    </xsl:call-template>
  </xsl:if>

  <xsl:if test="not(@RSLT_REF_CMT='')">
    <xsl:call-template name="generate-comments">
      <xsl:with-param name="result-column-start" select="$result-column-start"/>
    	<xsl:with-param name="full-row-column-start" select="$full-row-column-start"/>
      <xsl:with-param name="total-columns" select="$total-columns"/>
      <xsl:with-param name="comment-text" select="@RSLT_REF_CMT"/>
    </xsl:call-template>
  </xsl:if>
      
  <xsl:if test="not(@REMARK_TEXT='')">
    <xsl:call-template name="generate-comments">
      <xsl:with-param name="result-column-start" select="$result-column-start"/>
    	<xsl:with-param name="full-row-column-start" select="$full-row-column-start"/>
      <xsl:with-param name="total-columns" select="$total-columns"/>
      <xsl:with-param name="comment-text" select="@REMARK_TEXT"/>
    </xsl:call-template>
  </xsl:if>
 </xsl:template>

 <xsl:template name="csr">
     <fo:block text-align="center" space-after.optimum="0pt" space-before.optimum="0pt" break-before="page">    
      <fo:table>
        <xsl:if test="$print-csr-demographics-every-page='N'">
         <xsl:attribute name="table-omit-header-at-break">true</xsl:attribute>
        </xsl:if>
       <fo:table-column column-width="19.4cm" 
           border-bottom-color="#03845B" border-bottom-width="2pt" border-bottom-style="solid" 
       		 border-right-color="#03845B" border-right-width="1pt" border-right-style="solid"
       		 border-left-color="#03845B" border-left-width="1pt" border-left-style="solid"/>

   <xsl:if test="$csr-show-demographics='Y'">
		<xsl:call-template name="demographic-subheader-block"/>
   </xsl:if>
       
       <fo:table-body>
        <fo:table-row>
         <fo:table-cell>
          <fo:block text-align="start" font-family="Courier" font-size="8pt">
           
           <fo:table>

            <fo:table-column column-width="2.63cm"/>
            <fo:table-column column-width="4.02cm"/> <!-- see FoExampleWorksheet.xls for TOPCAT -> PDF column conversion -->
            <fo:table-column column-width="0.70cm"/>
            <fo:table-column column-width="0.52cm"/>
            <fo:table-column column-width="1.05cm"/>
            <fo:table-column column-width="0.52cm"/>
            <fo:table-column column-width="3.84cm"/>
            <fo:table-column column-width="3.49cm"/>
            <fo:table-column column-width="2.63cm"/>

            <fo:table-header>
             <fo:table-row>
              <fo:table-cell number-columns-spanned="9" background-color="#03845B" padding-left="1pt">
               <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="1pt"  font-size="10pt" color="white" 
                 border-bottom-color="white" border-bottom-width="2pt" border-bottom-style="solid" 
                 font-weight="bold" font-family="Helvetica">
                  <xsl:choose>
                   <xsl:when test="/Report/@CSR_TITLE and /Report/@CSR_TITLE!=''"><xsl:value-of select="/Report/@CSR_TITLE" /></xsl:when>
                   <xsl:otherwise>Clinical Significance Review</xsl:otherwise>
                  </xsl:choose>
                </fo:block>
              </fo:table-cell>
             </fo:table-row>

             <fo:table-row background-color="#03845B">
              <fo:table-cell />
              <fo:table-cell number-columns-spanned="7">
               <fo:block space-before.optimum="5pt"  space-after.optimum="3pt">
             
        <xsl:apply-templates select="Note[@NOTE_TYPE_ID='8']" mode="csr-header"/> 

               </fo:block>
              </fo:table-cell>
              <fo:table-cell />
             </fo:table-row>

            </fo:table-header>
        

            <fo:table-footer>
             <fo:table-row>
              <fo:table-cell />
              <fo:table-cell number-columns-spanned="7">
               <fo:block space-before.optimum="8pt"  space-after.optimum="8pt">
             
        <xsl:apply-templates select="Note[@NOTE_TYPE_ID='10']" mode="csr-footer"/>

               </fo:block>
              </fo:table-cell>
              <fo:table-cell />
             </fo:table-row>
            </fo:table-footer>
        
            <fo:table-body>
             <fo:table-row>
              <fo:table-cell number-columns-spanned="7">
               <fo:block space-before.optimum="4pt"  space-after.optimum="4pt" />
              </fo:table-cell>
              <fo:table-cell />
             </fo:table-row>
  
    		<xsl:choose>
    		 <xsl:when test="Test//Result[@CSR_IND='Y' and @BLIND_IND='N']">
          <xsl:apply-templates select="Test" mode="csr-results"/>  
    		 </xsl:when>
     		 <xsl:otherwise>
             <fo:table-row>
              <fo:table-cell />
              <fo:table-cell number-columns-spanned="7">
               <fo:block space-before.optimum="20pt"  space-after.optimum="20pt" text-align="start" font-size="8pt"  font-family="Courier"
                  font-weight="bold"><xsl:value-of select="/Report/@CSR_EMPTY_REMARK" /></fo:block>
              </fo:table-cell>
              <fo:table-cell />
             </fo:table-row>
    		 </xsl:otherwise>
    		</xsl:choose>
          
           </fo:table-body>
           </fo:table>
  
          </fo:block>
         </fo:table-cell>
        </fo:table-row>
       </fo:table-body>
      </fo:table>

     </fo:block>
     <fo:block id="last-csr-page"></fo:block>
  </xsl:template>

 <xsl:template match="Test" mode="csr-results">
   <xsl:if test="Result[@CSR_IND='Y' and @BLIND_IND='N']">
   
     <xsl:apply-templates select="Result[@CSR_IND='Y' and @BLIND_IND='N']" mode="csr-results"/>

   </xsl:if>
 </xsl:template>

 <xsl:template match="Result" mode="csr-results">

     <xsl:variable name="order-detail-on-same-row">
      <xsl:choose>
       <xsl:when test="/Report/@CSR_RESULT_COLUMN='Normal Column'">1</xsl:when>
       <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>
     </xsl:variable>

     <xsl:variable name="result-location">
      <xsl:choose>
       <xsl:when test="/Report/@CSR_RESULT_COLUMN='Report Body'">
     
        <xsl:choose>
         <xsl:when test="@CLINICAL_STATUS_CODE='H' or @CLINICAL_STATUS_CODE='L' or @CLINICAL_STATUS_CODE='A'
              or @CLINICAL_STATUS_CODE='Z' or @CLINICAL_STATUS_CODE='I'">6</xsl:when>
         <xsl:otherwise>4</xsl:otherwise>
        </xsl:choose>
       
       </xsl:when>
       <xsl:otherwise>
        
        <xsl:choose>
         <xsl:when test="/Report/@CSR_RESULT_COLUMN='Abnormal Column'">6</xsl:when>
         <xsl:otherwise>3</xsl:otherwise>
        </xsl:choose>
       
       </xsl:otherwise>
      </xsl:choose>
     </xsl:variable>

      
<!-- debugging

             <fo:table-row>
              <fo:table-cell number-columns-spanned="9">
               <fo:block space-before.optimum="5pt" text-align="start" font-size="8pt"  font-family="Courier">
              	position()=<xsl:value-of select="position()" />
              	count(../Result)=<xsl:value-of select="count(../Result)" />
              	../@SERVICE_DESC=<xsl:value-of select="../@SERVICE_DESC" />
              	@ITEM_DESC=<xsl:value-of select="@ITEM_DESC" /></fo:block>
              </fo:table-cell>
             </fo:table-row>
-->

      <xsl:if test="position()=1 and (count(../Result)!=1 or ../@SERVICE_DESC!=@ITEM_DESC)">
             <fo:table-row>
              <fo:table-cell />
              <fo:table-cell number-columns-spanned="7">
               <fo:block space-before.optimum="5pt" text-align="start" font-size="8pt"  font-family="Courier"
                  font-weight="bold"><xsl:value-of select="../@SERVICE_DESC" /></fo:block>
              </fo:table-cell>
              <fo:table-cell />
             </fo:table-row>
      </xsl:if>

        <fo:table-row>
         <fo:table-cell />

     <xsl:choose>
      <xsl:when test="position()=1 and (count(../Result)=1 and ../@SERVICE_DESC=@ITEM_DESC)">
         <fo:table-cell>
          <fo:block space-before.optimum="2pt" font-family="Courier" font-weight="bold" font-size="8pt" text-align="start">
           <xsl:value-of select="@ITEM_DESC" /></fo:block>
         </fo:table-cell>
      </xsl:when>
      <xsl:otherwise>
         <fo:table-cell>
          <fo:block space-before.optimum="2pt" font-family="Courier" font-size="8pt" text-align="start">&#xA0;<xsl:value-of select="@ITEM_DESC" /></fo:block>
         </fo:table-cell>
      </xsl:otherwise>
     </xsl:choose>

         <fo:table-cell number-columns-spanned="{1 + ($result-location - 3)}">
          <fo:block font-family="Courier" font-size="8pt" color="red" text-align="start">

           <xsl:choose>
            <xsl:when test="/Report/@CSR_TOX_RESULTS!='Y' or @TOXICITY='' or not(@TOXICITY)">&#xA0;&#xA0;&#xA0;</xsl:when>
            <xsl:otherwise><xsl:value-of select="@TOXICITY" /></xsl:otherwise>
           </xsl:choose>

            <xsl:if test="/Report/@CSR_PRINT_DELTA='Y'">
             <xsl:value-of select="@DELTA_IND" />
            </xsl:if>

          </fo:block>
         </fo:table-cell>
         <fo:table-cell number-columns-spanned="{1 + (6 - $result-location) - $order-detail-on-same-row*(2)}">
          <fo:block font-family="Courier" font-size="8pt" text-align="start">
            <xsl:if test="/Report/@CSR_PRINT_STARS='Y'">
             <xsl:value-of select="@ALERT_FLAG" />
            </xsl:if>
          	<xsl:value-of select="@RSLT_VALUE" />
          </fo:block>
         </fo:table-cell>
         
      <xsl:choose>
       <xsl:when test="$order-detail-on-same-row='1'">
         <fo:table-cell number-columns-spanned="3">
          <fo:block font-family="Courier" font-size="8pt" text-align="start">
           <xsl:apply-templates select="../../Note[@NOTE_TYPE_ID='9']" mode="csr-detail-text"/>
          </fo:block>
         </fo:table-cell>
       </xsl:when>
       <xsl:otherwise>
         <fo:table-cell>
          <xsl:if test="/Report/@CSR_PRINT_REFERENCE='Y' and @REF_RANGE_CMT!=''">
           <fo:block font-family="Courier" font-size="8pt" text-align="start">
            <xsl:value-of select="@REF_RANGE_CMT" />
           </fo:block>
          </xsl:if>
         </fo:table-cell>
       </xsl:otherwise>
      </xsl:choose>

         <fo:table-cell />
        </fo:table-row>

    <xsl:choose>
     <xsl:when test="$order-detail-on-same-row='0'">
      <xsl:if test="/Report/@CSR_PRINT_REFERENCE='Y' and @REF_RANGE_CMT2!=''">
        <fo:table-row>
         <fo:table-cell />
         <fo:table-cell number-columns-spanned="6"/>
         <fo:table-cell>
           <fo:block font-family="Courier" font-size="8pt" text-align="start">
            <xsl:value-of select="@REF_RANGE_CMT2" />
           </fo:block>
         </fo:table-cell>
         <fo:table-cell />
        </fo:table-row>
      </xsl:if>

        <fo:table-row>
         <fo:table-cell />
         <fo:table-cell number-columns-spanned="4"/>
         <fo:table-cell number-columns-spanned="3">
          <fo:block font-family="Courier" font-size="8pt" text-align="start">
           <xsl:apply-templates select="../../Note[@NOTE_TYPE_ID='9']" mode="csr-detail-text"/>
          </fo:block>
         </fo:table-cell>
         <fo:table-cell />
        </fo:table-row>
    </xsl:when>
    <xsl:otherwise>
      <xsl:if test="/Report/@CSR_PRINT_REFERENCE='Y' and @REF_RANGE_CMT!=''">
        <fo:table-row>
        <fo:table-cell />
         <fo:table-cell number-columns-spanned="6"/>
         <fo:table-cell>
           <fo:block font-family="Courier" font-size="8pt" text-align="start">
            <xsl:value-of select="@REF_RANGE_CMT" />
           </fo:block>
         </fo:table-cell>
         <fo:table-cell />
        </fo:table-row>
      </xsl:if>

      <xsl:if test="/Report/@CSR_PRINT_REFERENCE='Y' and @REF_RANGE_CMT2!=''">
        <fo:table-row>
         <fo:table-cell />
         <fo:table-cell number-columns-spanned="6"/>
         <fo:table-cell>
           <fo:block font-family="Courier" font-size="8pt" text-align="start">
            <xsl:value-of select="@REF_RANGE_CMT2" />
           </fo:block>
         </fo:table-cell>
         <fo:table-cell />
        </fo:table-row>
      </xsl:if>
     </xsl:otherwise>
    </xsl:choose>


    <fo:table-row>
         <fo:table-cell number-columns-spanned="9"><fo:block space-after.optimum="4pt"/></fo:table-cell>
    </fo:table-row>

 </xsl:template>

 <xsl:template match="Note" mode="csr-header">
       <fo:block white-space-collapse="false" text-align="start" font-size="8pt" font-weight="bold" color="white"
                 font-family="Courier">&#xA0;&#xA0;<xsl:value-of select="@NOTE_DESC" /></fo:block>
 </xsl:template>

 <xsl:template match="Note" mode="csr-footer">
       <fo:block white-space-collapse="false" text-align="start" font-size="8pt" font-weight="bold"
                 font-family="Courier">&#xA0;&#xA0;<xsl:value-of select="@NOTE_DESC" /></fo:block>
 </xsl:template>

 <xsl:template match="Note" mode="csr-detail-text">
               <fo:block text-align="start" white-space-collapse="false" font-size="8pt" 
                  font-family="Courier"><xsl:value-of select="@NOTE_DESC" /></fo:block>
 </xsl:template>

 <xsl:template name="demographic-subheader-block">
        
       <fo:table-header>
        <fo:table-row>
         <fo:table-cell>
          <fo:block text-align="center" space-after.optimum="0pt" space-before.optimum="0pt">
           <fo:table>
            <fo:table-column column-width="9.7cm"/>
            <fo:table-column column-width="9.7cm"/>
            <fo:table-body>
             <fo:table-row>
              <fo:table-cell background-color="#03845B" padding-left="1pt" number-columns-spanned="2">
               <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="1pt"  font-size="10pt" color="white" 
                  font-weight="bold">Demographics</fo:block>
              </fo:table-cell>
             </fo:table-row>
             <fo:table-row>

<!-- demo/subheader switch functionality -->
    		<xsl:choose>
    		 <xsl:when test="$show-demographics-on-right='N'">
       		<xsl:call-template name="demographics" />
       		<xsl:call-template name="subheader" />
    		 </xsl:when>
     		 <xsl:otherwise>
       		<xsl:call-template name="subheader" />
       		<xsl:call-template name="demographics" />
    		 </xsl:otherwise>
    		</xsl:choose>

             </fo:table-row>
            </fo:table-body>
           </fo:table>
          
          </fo:block>    
         </fo:table-cell>
        </fo:table-row>
       </fo:table-header>
 </xsl:template>

 <xsl:template name="demographics">

         <fo:table-cell padding-left="1pt" border-right-color="#03845B" border-right-width=".5pt" border-right-style="solid">
          <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="5pt" font-size="8pt">
            
           <fo:table>
            <fo:table-column column-width="4.4cm"/>
            <fo:table-column column-width="4.3cm"/>
            <fo:table-body>
             
     <xsl:apply-templates select="Demo"/>

            </fo:table-body>
           </fo:table>
       
          </fo:block>
         </fo:table-cell>
 </xsl:template>

 <xsl:template match="Demo">
             <fo:table-row>
              <fo:table-cell>
               <fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold">&#xA0;<xsl:value-of select="@PROMPT_DESC" /></fo:block>
              </fo:table-cell>
              <fo:table-cell>
               <fo:block text-align="start" font-size="8pt" font-family="Courier"><xsl:value-of select="@PROMPT_VALUE" /></fo:block>
              </fo:table-cell>
            </fo:table-row>
 </xsl:template>

 <xsl:template name="subheader">
         <fo:table-cell padding-left="2pt">
          <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="5pt" 
            font-family="Courier" font-weight="bold" font-size="8pt">
		
		<xsl:choose>
		 <xsl:when test="$report-date!=''">
  
  		<xsl:choose>
		   <xsl:when test="$report-status-code='T'">
        <xsl:value-of select="$temp-subheader-disclaimer" />
		   </xsl:when>
		   <xsl:otherwise>
        <xsl:apply-templates select="Note" mode="subheader" />
		   </xsl:otherwise>
      </xsl:choose>

	   </xsl:when>
     <xsl:otherwise>
		
		  <xsl:choose>
		   <xsl:when test="$any-hold='Y'">
         <xsl:value-of select="$subheader-disclaimer-1" />
		   </xsl:when>
		   <xsl:otherwise>
         <xsl:value-of select="$pending-subheader-disclaimer" />
		   </xsl:otherwise>
      </xsl:choose>
		 
		 </xsl:otherwise>
    </xsl:choose>

          &#xA0;</fo:block>
         </fo:table-cell>
 </xsl:template>

 <xsl:template match="Note" mode="subheader">
     <xsl:if test="@NOTE_TYPE_ID=7">
          <xsl:value-of select="@NOTE_DESC" />
     </xsl:if>
 </xsl:template>

 <xsl:template name="quick-visit-history">
     <fo:block text-align="center" space-after.optimum="0pt" space-before.optimum="0pt" break-before="page">    

      <fo:table>
        <xsl:if test="$print-qt-qvh-demographics-every-page='N'">
         <xsl:attribute name="table-omit-header-at-break">true</xsl:attribute>
        </xsl:if>
       
       <fo:table-column column-width="19.4cm" 
       		 border-bottom-color="#03845B" border-bottom-width="1pt" border-bottom-style="solid"
       		 border-right-color="#03845B" border-right-width="1pt" border-right-style="solid"
       		 border-left-color="#03845B" border-left-width="1pt" border-left-style="solid"/>

		<xsl:call-template name="demographic-subheader-block"/>

       <fo:table-body>
        <fo:table-row>
         <fo:table-cell>

     <xsl:apply-templates select="QuickViews"/>  

         </fo:table-cell>
        </fo:table-row>
       </fo:table-body>
      </fo:table>
     </fo:block>
 </xsl:template>

 <xsl:template match="QuickViews">
     <fo:block text-align="center" space-after.optimum="5pt" space-before.optimum="0pt">    

      <fo:table>
       <fo:table-column column-width="1.35in"/> <!-- see FoExampleWorksheet.xls for TOPCAT -> PDF column conversion -->
       <fo:table-column column-width="1.30in"/>
       <fo:table-column column-width="1.25in"/>
       <fo:table-column column-width="1.75in"/>
       <fo:table-column column-width="1.00in"/>
       <fo:table-column column-width="0.98in"/>

       <fo:table-header>

        <fo:table-row>
         <fo:table-cell background-color="#03845B" padding-left="1pt" number-columns-spanned="6">
          <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="1pt"  font-size="10pt" color="white" 
            border-bottom-color="white" border-bottom-width="2pt" border-bottom-style="solid" 
            font-weight="bold">Quick Visit History</fo:block>
         </fo:table-cell>
        </fo:table-row>

        <fo:table-row background-color="#03845B"  text-align="start" font-size="8pt" color="white" font-weight="bold">
         <fo:table-cell padding-left="1pt">
          <fo:block space-before.optimum="1pt"  space-after.optimum="1pt"><xsl:value-of select="../@PID1_TITLE" /></fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block space-before.optimum="1pt"  space-after.optimum="1pt"><xsl:value-of select="../@PID2_TITLE" /></fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block space-before.optimum="1pt"  space-after.optimum="1pt">Visit</fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block space-before.optimum="1pt"  space-after.optimum="1pt">Visit Type</fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block space-before.optimum="1pt"  space-after.optimum="1pt">Coll. Date</fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block space-before.optimum="1pt"  space-after.optimum="1pt">Req #</fo:block>
         </fo:table-cell>
        </fo:table-row>
 
        <fo:table-row>
         <fo:table-cell number-columns-spanned="6" >
          <fo:block font-size="6pt">&#xA0;</fo:block>
         </fo:table-cell>
        </fo:table-row>

       </fo:table-header>

       <fo:table-body>
       
     <xsl:apply-templates select="QuickView"/>  

       </fo:table-body>
      </fo:table>
     </fo:block>

 </xsl:template>


 <xsl:template match="QuickView">

      <xsl:if test="not($qvh-this-visit='N' and @REQ_NUMBER=/Report/@REQ_NUMBER)">
        <fo:table-row text-align="start" font-size="8pt" font-family="Courier">
         <fo:table-cell padding-left="1pt">
          <fo:block font-weight="bold"><xsl:value-of select="@PRIMARY_ID" /></fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block><xsl:value-of select="@SECONDARY_ID" /></fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block><xsl:value-of select="@VISIT_CODE" /></fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block><xsl:value-of select="@VISIT_TYPE_CODE" /></fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block><xsl:value-of select="@COLLECT_DATE" /></fo:block>
         </fo:table-cell>
         <fo:table-cell>
          <fo:block><xsl:value-of select="@REQ_NUMBER" /></fo:block>
         </fo:table-cell>
        </fo:table-row>
      </xsl:if>
 </xsl:template>

 <xsl:template match="Note" mode="report-footer">
             <fo:table-row font-family="Courier" keep-with-next="always">
              <fo:table-cell />
              <fo:table-cell number-columns-spanned="7">
               <fo:block text-align="start" font-size="8pt" font-family="Courier">
                <xsl:value-of select="@NOTE_DESC" />
               </fo:block>
              </fo:table-cell>
             </fo:table-row>
 </xsl:template>

 <xsl:template match="Note" mode="report-comments">
          <fo:block text-align="start" space-before.optimum="3pt"  space-after.optimum="3pt"  font-size="8pt" 
            font-family="Courier"><xsl:value-of select="@NOTE_DESC" /></fo:block>
 </xsl:template>

 <xsl:template name="quick-trend">
     <fo:block text-align="center" space-after.optimum="0pt" space-before.optimum="0pt" break-before="page">    

      <fo:table>
        <xsl:if test="$print-qt-qvh-demographics-every-page='N'">
         <xsl:attribute name="table-omit-header-at-break">true</xsl:attribute>
        </xsl:if>
       
       <fo:table-column column-width="19.4cm" 
           border-bottom-color="#03845B" border-bottom-width="2pt" border-bottom-style="solid" 
       		 border-right-color="#03845B" border-right-width="1pt" border-right-style="solid"
       		 border-left-color="#03845B" border-left-width="1pt" border-left-style="solid"/>

		<xsl:call-template name="demographic-subheader-block"/>

       <fo:table-body>
        <fo:table-row>
         <fo:table-cell>
          <fo:block text-align="center" space-after.optimum="0pt" space-before.optimum="0pt">    
       
           <fo:table>
             <fo:table-column column-width="9.7cm"/>
             <fo:table-column column-width="9.7cm"/>
        
            <fo:table-header>
       
             <fo:table-row>
              <fo:table-cell background-color="#03845B" padding-left="1pt" number-columns-spanned="2">
               <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="2pt"  font-size="10pt" color="white" 
                 font-weight="bold">Quick
	      <xsl:choose>
       	<xsl:when test="$quick-retest-flag='Y'">Retest</xsl:when>
       	<xsl:otherwise>Trend</xsl:otherwise>
        </xsl:choose>
               </fo:block>
              </fo:table-cell>
             </fo:table-row>
       
             <fo:table-row>
              <fo:table-cell padding-left="1pt">
               <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="5pt" font-size="8pt" />
              </fo:table-cell>
              <fo:table-cell padding-left="2pt">
               <fo:block text-align="start" space-before.optimum="5pt"  space-after.optimum="5pt"  font-size="8pt"></fo:block>
              </fo:table-cell>
             </fo:table-row>
	     	    <fo:table-row>
	             <fo:table-cell padding-left="1pt" number-columns-spanned="2" font-family="Courier"  text-align="center" font-size="8pt">
	     	          <fo:block>NOTE: THE QUICK 
	      <xsl:choose>
       	<xsl:when test="$quick-retest-flag='Y'">RETEST</xsl:when>
       	<xsl:otherwise>TREND</xsl:otherwise>
        </xsl:choose>
                             REPORT MAY CONTAIN TRUNCATED TEXT RESULT(S)!</fo:block>
      	          <fo:block>PLEASE, REFER TO THE ACTUAL LAB REPORT FOR COMPLETE RESULT(S)...</fo:block>
	     	          <fo:block>@ DENOTES ABNORMAL RESULTS</fo:block>
	     	          <fo:block>&#xA0;</fo:block>
	             </fo:table-cell>
             </fo:table-row>
            </fo:table-header>
       
            <fo:table-body>
       
    <!--  
         <xsl:for-each select="key('mod-five-list', 1)">
            <fo:table-row>
       
	     	<xsl:call-template name="QuickTrendBlock">
	     		<xsl:with-param name="minBlock" select="number(@REPORT_SEQ)-1"/>
	     	</xsl:call-template>
       
             </fo:table-row>
          	</xsl:for-each>
     -->
         
          <xsl:for-each select="//QuickTrend">
           <xsl:if test="position() mod 5 = '1'">
           
                <fo:table-row>
                 <xsl:call-template name="QuickTrendBlock">
                  <xsl:with-param name="minBlock" select="position() - 1"/>
                 </xsl:call-template>
                </fo:table-row>
           
           </xsl:if>
          </xsl:for-each>
	
	
            </fo:table-body>
           </fo:table>
          
          </fo:block>    
         </fo:table-cell>
        </fo:table-row>
       </fo:table-body>
      </fo:table>
     </fo:block>
 </xsl:template>

	<xsl:template name="QuickTrendBlock">
         <fo:table-cell padding-left="1pt" number-columns-spanned="2"   font-family="Courier"  text-align="center" font-size="8pt">
   <xsl:if test="position()!=1" >
		      <fo:block  break-before="page"/>
   </xsl:if>

		      <fo:block>
		      <fo:table>
		            <fo:table-column column-width="5.4cm"/>
		             <fo:table-column column-width="2.8cm"/>
		             <fo:table-column column-width="2.8cm"/>
		             <fo:table-column column-width="2.8cm"/>
		             <fo:table-column column-width="2.8cm"/>
		             <fo:table-column column-width="2.8cm"/>
		      <fo:table-header>
		      <xsl:param name="minBlock"/>
              	<fo:table-row>
             		<xsl:for-each select="//QuickTrend">
            			<xsl:variable name="reportSequence" select="@REPORT_SEQ"/>
            			<xsl:variable name="sequence" select="position()"/>
            			<xsl:if test="$minBlock &lt; $sequence">
            				<xsl:if test="$minBlock+6 &gt; $sequence">
		            			<xsl:call-template name="RequisitionHeading">
		            				<xsl:with-param name="reportSequence" select="$reportSequence"/>
		            				<xsl:with-param name="sequence" select="$sequence"/>
		            			</xsl:call-template>
	            			</xsl:if>
            			</xsl:if>
		      </xsl:for-each>
		      </fo:table-row>
		      <fo:table-row>
		      <xsl:for-each select="//QuickTrend">
            			<xsl:variable name="reportSequence" select="@REPORT_SEQ"/>
            			<xsl:variable name="sequence" select="position()"/>
            			<xsl:if test="$minBlock &lt; $reportSequence">
            				<xsl:if test="$minBlock+6 &gt; $sequence">
		            			<xsl:call-template name="RequisitionVisitDate">
		            				<xsl:with-param name="reportSequence" select="$reportSequence"/>
		            				<xsl:with-param name="sequence" select="$sequence"/>
		            			</xsl:call-template>
		            		</xsl:if>
		            	</xsl:if>
		      </xsl:for-each>
		      </fo:table-row>
		      <fo:table-row>
             		<xsl:for-each select="//QuickTrend">
      				<xsl:variable name="reportSequence" select="@REPORT_SEQ"/>
            			<xsl:variable name="sequence" select="position()"/>
	            			<xsl:if test="$minBlock &lt; $sequence">
	            				<xsl:if test="$minBlock+6 &gt; $sequence">
		      				<xsl:call-template name="RequisitionVisit">
		      	      				<xsl:with-param name="reportSequence" select="$reportSequence"/>
		            				<xsl:with-param name="sequence" select="$sequence"/>
		      	      			</xsl:call-template>
		      	      		</xsl:if>
		      	      	</xsl:if>
		      	</xsl:for-each>
		      </fo:table-row>
		      <fo:table-row>
              	<xsl:for-each select="//QuickTrend">
            			<xsl:variable name="reportSequence" select="@REPORT_SEQ"/>
            			<xsl:variable name="sequence" select="position()"/>
            			<xsl:if test="$minBlock &lt; $sequence">
            				<xsl:if test="$minBlock+6 &gt; $sequence">
		      			<xsl:call-template name="RequisitionVisitType">
		            				<xsl:with-param name="reportSequence" select="$reportSequence"/>
		            				<xsl:with-param name="sequence" select="$sequence"/>
		            			</xsl:call-template>
		            		</xsl:if>
		            	</xsl:if>
             	</xsl:for-each>
		      </fo:table-row>
		      </fo:table-header>
		      <fo:table-body>
		      	<xsl:for-each select="//QuickTrend[1]">
   	      			<xsl:apply-templates select="./QuickTrendTest">
   	      				<xsl:with-param name="minBlock" select="$minBlock"/>
   	      			</xsl:apply-templates>
		      	</xsl:for-each>
		      </fo:table-body>
	       </fo:table>
	      </fo:block>
	     </fo:table-cell>
	</xsl:template>

	<xsl:template name="RequisitionHeading">
		<xsl:param name="sequence"/>
		<xsl:param name="reportSequence"/>
		<xsl:for-each select="key('report-sequence', $reportSequence)">
			<xsl:if test="$sequence mod 5='1'">
			<fo:table-cell>
				<fo:block text-align="end" font-size="8pt" font-family="Courier" font-weight="bold">REQ#:&#xA0;</fo:block>
			</fo:table-cell>
			</xsl:if>
			<fo:table-cell>
				<fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="./@REQ_NUMBER"/></fo:block>
			</fo:table-cell>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template name="RequisitionVisitDate">
		<xsl:param name="sequence"/>
		<xsl:param name="reportSequence"/>
		<xsl:for-each select="key('report-sequence', $reportSequence)">
			<xsl:if test="$sequence mod 5='1'">
				<fo:table-cell>
					<fo:block text-align="end" font-size="8pt" font-family="Courier" font-weight="bold">VISIT DATE:&#xA0;</fo:block>
				</fo:table-cell>
			</xsl:if>
			<fo:table-cell>
				<fo:block text-align="start" font-size="8pt" font-family="Courier"><xsl:value-of select="./@VISIT_DATE"/></fo:block>
			</fo:table-cell>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template name="RequisitionVisit">
		<xsl:param name="sequence"/>
		<xsl:param name="reportSequence"/>
		<xsl:for-each select="key('report-sequence', $reportSequence)">
			<xsl:if test="$sequence mod 5='1'">
				<fo:table-cell>
					<fo:block text-align="end" font-size="8pt" font-family="Courier" font-weight="bold">VISIT:&#xA0;</fo:block>
				</fo:table-cell>
			</xsl:if>
			<fo:table-cell>
				<fo:block text-align="start" font-size="8pt" font-family="Courier"><xsl:value-of select="./@VISIT_CODE"/></fo:block>
			</fo:table-cell>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="RequisitionVisitType">
		<xsl:param name="sequence"/>
		<xsl:param name="reportSequence"/>
		<xsl:for-each select="key('report-sequence', $reportSequence)">
			<xsl:if test="$sequence mod 5='1'">
				<fo:table-cell>
					<fo:block text-align="end" font-size="8pt" font-family="Courier" font-weight="bold">VISIT TYPE:&#xA0;</fo:block>
				</fo:table-cell>
			</xsl:if>
			<fo:table-cell>
				<fo:block text-align="start" font-size="8pt" font-family="Courier"><xsl:value-of select="./@VISIT_TYPE_NAME"/></fo:block>
			</fo:table-cell>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="QuickTrendTest">
		<xsl:param name="minBlock"/>
		<xsl:param name="serviceId" select="./@SERVICE_ID"/>
		<fo:table-row>
	       	<fo:table-cell padding-left="1pt" number-columns-spanned="6"   font-family="Courier"  text-align="center" font-size="8pt">
	       	<fo:block >
	       	<fo:table>
		      <fo:table-column column-width="5.4cm"/>
		       <fo:table-column column-width="2.8cm"/>
		       <fo:table-column column-width="2.8cm"/>
		       <fo:table-column column-width="2.8cm"/>
		       <fo:table-column column-width="2.8cm"/>
		       <fo:table-column column-width="2.8cm"/>
		      <fo:table-header>
	      		<fo:table-row>
	      			<fo:table-cell number-columns-spanned="6"><fo:block>&#xA0;</fo:block></fo:table-cell></fo:table-row>
	     		<fo:table-row><fo:table-cell ><fo:block>&#xA0;</fo:block></fo:table-cell></fo:table-row>

      <xsl:if test="(count(QuickTrendAnalyte)!=1 or @SERVICE_DESC!=./QuickTrendAnalyte/@ITEM_DESC)">
		      <fo:table-row>
		        <fo:table-cell number-columns-spanned="6">
			       	<fo:block text-align="start" font-size="8pt" font-family="Courier" font-weight="bold"><xsl:value-of select="./@SERVICE_DESC"/></fo:block>
			      </fo:table-cell>
	       	</fo:table-row>
      </xsl:if>

       	</fo:table-header>
       	<fo:table-body>
		<xsl:for-each select="./QuickTrendAnalyte">
			<fo:table-row>
				<xsl:call-template name="requisitionList">
					<xsl:with-param name="analyteId" select="./@ANALYTE_ID"/>
					<xsl:with-param name="resultPrintSequence" select="./@RSLT_PRINT_SEQ"/>
					<xsl:with-param name="serviceId" select="$serviceId"/>
					<xsl:with-param name="minBlock" select="$minBlock"/>
				</xsl:call-template>
			</fo:table-row>
		</xsl:for-each>
		</fo:table-body>
		</fo:table>
		</fo:block>
		</fo:table-cell>
		</fo:table-row>
	</xsl:template>

	<xsl:template name="requisitionList">
		<xsl:param name="analyteId"/>
		<xsl:param name="serviceId"/>
		<xsl:param name="resultPrintSequence"/>
		<xsl:param name="minBlock"/>
		<xsl:for-each select="//QuickTrend">
			<xsl:variable name="sequence" select="position()"/>
			<xsl:variable name="reportSequence" select="./@REPORT_SEQ"/>
			<xsl:if test="$sequence &gt; $minBlock">
				<xsl:if test="$sequence &lt; $minBlock+6">
		        		<xsl:call-template name="reportSequence">
		        			<xsl:with-param name="sequence" select="$sequence"/>
			 			<xsl:with-param name="reportSequence" select="$reportSequence"/>
			 			<xsl:with-param name="analyteId" select="$analyteId"/>
			 			<xsl:with-param name="serviceId" select="$serviceId"/>
			 			<xsl:with-param name="resultPrintSequence" select="$resultPrintSequence"/>
			 		</xsl:call-template>
			 	</xsl:if>
		 	</xsl:if>
 		</xsl:for-each>
	</xsl:template>
	
	<xsl:template name="reportSequence">
		<xsl:param name="sequence"/>
		<xsl:param name="reportSequence"/>
		<xsl:param name="analyteId"/>
		<xsl:param name="serviceId"/>
		<xsl:param name="resultPrintSequence"/>
	       <xsl:for-each select="key('analyte-by-id', $analyteId)">
       		<xsl:call-template name="QuickTrendAnalyte">
       			<xsl:with-param name="sequence" select="$sequence"/>
       			<xsl:with-param name="analyteId" select="$analyteId"/>
       			<xsl:with-param name="reportSequence" select="$reportSequence"/>
       			<xsl:with-param name="serviceId" select="$serviceId"/>
       			<xsl:with-param name="resultPrintSequence" select="$resultPrintSequence"/>
       		</xsl:call-template>
	       </xsl:for-each>
	</xsl:template>

	<xsl:template name="QuickTrendAnalyte">
		<xsl:param name="sequence"/>
		<xsl:param name="reportSequence"/>
		<xsl:param name="analyteId"/>
		<xsl:param name="serviceId"/>
		<xsl:param name="resultPrintSequence"/>
		<xsl:param name="minBlock"/>
		<xsl:if test="$sequence mod 5='1'">

     <xsl:choose>
      <xsl:when test="(count(../QuickTrendAnalyte)=1 and ../@SERVICE_DESC=@ITEM_DESC)">
	     <fo:table-cell>
				 <fo:block text-align="start" font-weight="bold" font-size="8pt" font-family="Courier">&#xA0;
					<xsl:value-of select="@ITEM_DESC"/>
				 </fo:block>
    	 </fo:table-cell>
      </xsl:when>

      <xsl:otherwise>
	     <fo:table-cell>
        <xsl:for-each select="key('analyte-by-id', $analyteId)">
				 <fo:block text-align="start" font-size="8pt" font-family="Courier">&#xA0;&#xA0;
					<xsl:value-of select="@ITEM_DESC"/>
				 </fo:block>
    	  </xsl:for-each>
    	 </fo:table-cell>
      </xsl:otherwise>
     </xsl:choose>

     </xsl:if>
     
     <fo:table-cell>
       <fo:block text-align="start" font-size="8pt" font-family="Courier">
      	<xsl:call-template name="QuickTrendResult">
       		<xsl:with-param name="reportSequence" select="$reportSequence"/>
       		<xsl:with-param name="analyteId" select="$analyteId"/>
       		<xsl:with-param name="serviceId" select="$serviceId"/>
       		<xsl:with-param name="resultPrintSequence" select="$resultPrintSequence"/>
       	</xsl:call-template>
      	</fo:block>
     </fo:table-cell>
	</xsl:template>
	
	<xsl:template name="QuickTrendResult">
		<xsl:param name="analyteId"/>
		<xsl:param name="reportSequence"/>
		<xsl:param name="serviceId"/>
		<xsl:param name="resultPrintSequence"/>
		<!-- for each result for the current analyte -->
		<xsl:for-each select="key('result-by-id', $analyteId)">
			<xsl:if test="./@SERVICE_ID=$serviceId">
				<xsl:if test="./@REPORT_SEQ=$reportSequence">
					<xsl:if test="./@RSLT_PRINT_SEQ=$resultPrintSequence">
						<xsl:value-of select="./@RSLT_VALUE"/>
					</xsl:if>
				</xsl:if>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>

 <xsl:template name="setNewLine">
	<fo:block  text-align="start"  font-size="8pt">
	<xsl:param name="string" />
		<xsl:if test="contains($string, '^')">
			<xsl:value-of  select="substring-before($string, '^')" />
			<xsl:call-template name="setNewLine">
				<xsl:with-param name="string" select="substring-after($string, '^')" />
			</xsl:call-template>
		</xsl:if>
		<xsl:if test="not(contains($string, '^'))">
		 <xsl:value-of select="$string" />
	  </xsl:if>
	</fo:block>
 </xsl:template>

</xsl:stylesheet>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to