<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">

<xsl:output indent="yes" />

<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                              root                                 -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls formatting of the rap sheet by matching the
       document root.  The second tier of formatting is controlled by the
       /rapSheet template.
-->

<xsl:template match="/">
<HTML>

  <HEAD> 
    <TITLE>
    </TITLE>
    <STYLE>
      BODY { background-color: white; color: black;
             font-size: 10pt; font-family: Arial, Helvetica, sans-serif; 
             vertical-align: baseline; }
      H1 { font-size: 2.0em; font-weight:bold; color: #000080; }
      H2 { font-size: 1.6em; font-weight:bold; color: #000080; }
      H3 { font-size: 1.3em; font-weight:normal; }
      H4 { font-size: 1.0em; font-weight:bold; }
      H5 { font-size: 0.9em; font-weight:bold; }
      P  { vertical-align: text-top; }
      TABLE { border: 0pt; }
      TD { vertical-align: text-top; }
	   P.break { page-break-before: always }
    </STYLE>
  </HEAD>

  <BODY>
	   <xsl:apply-templates select="/publicRapSheet/introduction"/>
	  <xsl:apply-templates select="/publicRapSheet/response"/>	  
    <xsl:apply-templates select="/publicRapSheet/rapSheet"/>
  </BODY>

</HTML>

</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                            rapSheet                               -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls second tier formatting of the rap sheet 
       by generating the top level headings and then calling next tier
       templates for format those sections.
-->





<xsl:template match="/publicRapSheet/rapSheet">
  <H2><A NAME="identification">Identification</A></H2>
  <xsl:apply-templates select="person"/>

  <BR/><H2><A NAME="history">Criminal History</A></H2>
  <xsl:call-template name="cycle"/>

  <BR/><H2><A NAME="index">Index of Agencies</A></H2>
  <xsl:apply-templates select="agencyIndex"/>

</xsl:template>




<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                          navigation-bar                           -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls formatting of a navigation bar of hyperlinks
       to the various sections.  This allows easy switching from one part
       to another.
       This version is actually null and the real navigation bar is
       generated in the following template.
-->

<xsl:template name="navigation-bar">
</xsl:template>


<xsl:template match="response">
<p>&#160;</p>
<p>&#160;</p>
<table width="100%">
	<tbody>
		<tr>
			<th align="left"> <xsl:value-of
select="normalize-space(Description)"/></th>
		</tr>
	</tbody>
</table> 
</xsl:template>





<!--   This template controls second tier formatting of the rap sheet 
       by generating the top level headings and then calling next tier
       templates for format those sections.
-->



<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                          navigation-bar                           -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls formatting of a navigation bar of hyperlinks
       to the various sections.  This allows easy switching from one part
       to another.
-->

<xsl:template name="navigation-bar-for-real">
  <HR/>
  <TABLE BORDER="0" CELLPADDING="0" WIDTH="100%">
  <TR>
  <TD><A HREF="#introduction"><strong>Introduction</strong></A></TD>
  <TD><A HREF="#identification"><strong>Identification</strong></A></TD>
  <TD><A HREF="#history"><strong>Criminal History</strong></A></TD>
  <TD><A HREF="#index"><strong>Agencies</strong></A></TD>
  </TR>
  </TABLE>
  <HR/>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                           introduction                            -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls formatting of information from the 
       introduction element.  It is called from the /rapSheet template.
-->

<xsl:template match="introduction">
 <CENTER><H1>Criminal History Record</H1></CENTER>
 <H2><A NAME="introduction">Introduction</A></H2>
  <xsl:for-each select="request">
    <TABLE BORDER="0" WIDTH="100%">
      <xsl:if test="position()=1">
        <TR>
          <TD COLSPAN="2">
            <B>This rap sheet was produced in response to 
               the following request


              <xsl:if test="/publicRapSheet/@referenceDate!=''">
                <xsl:text> ( Produced on </xsl:text>
                <xsl:value-of select="normalize-space(/publicRapSheet/@referenceDate)"/>
                <xsl:text> )</xsl:text>
              </xsl:if>
			  			   			   
			   :
            </B>
          </TD>
        </TR>
      </xsl:if>

      <xsl:if test="position()>1">
        <TR>
          <TD><BR/><B>Additional Request:</B></TD>
        </TR>
      </xsl:if>

      <xsl:if test="count(../inquiry/inquiryName)>0">
        <TR>
          <TD>Inquiries Name(s)</TD>
          <TD>
            <xsl:for-each select="../inquiry/inquiryName">
              <DIV>
              <xsl:value-of select="normalize-space(.)"/>
			  	(<xsl:value-of select="normalize-space(../birthDate)"/>)		
				 <xsl:value-of select="normalize-space(../ssn)"/>		
              </DIV>
            </xsl:for-each>
          </TD>
        </TR>
      </xsl:if>

      <xsl:if test="./fbiNumber!=''">
        <TR>
          <TD WIDTH="34%">FBI Number</TD>
          <TD WIDTH="66%">
            <xsl:value-of select="normalize-space(./fbiNumber)"/>
          </TD>
        </TR>
      </xsl:if>

      <xsl:if test="./stateBureauIDNumber!=''">
         <TR>
           <TD WIDTH="34%">State ID Number</TD>
           <TD WIDTH="66%">
             <xsl:value-of select="normalize-space(./stateBureauIDNumber)"/>
             <xsl:call-template name="format-attributes">
               <xsl:with-param name="node" select="./stateBureauIDNumber"/>
             </xsl:call-template>
           </TD>
         </TR>
      </xsl:if>

      <xsl:if test="count(./ssn)>0">
         <TR>
           <TD>Social Security Number</TD>
           <TD>
             <xsl:for-each select="./ssn">
               <DIV><xsl:value-of select="normalize-space(.)"/></DIV>
             </xsl:for-each>
           </TD>
         </TR>
      </xsl:if>

      <xsl:if test="count(./dlNumber)>0">
         <TR>
           <TD>Driver&apos;s License Number</TD>
           <TD>
             <xsl:for-each select="./dlNumber">
               <DIV>
               <xsl:value-of select="normalize-space(.)"/>
               <xsl:call-template name="format-attributes"/>
               </DIV>
             </xsl:for-each>
           </TD>
         </TR>
      </xsl:if>

      <xsl:if test="count(./personalIDNumber)>0">
        <TR>
          <TD>Miscellaneous Number</TD>
          <TD>
            <xsl:for-each select="./personalIDNumber">
              <DIV>
              <xsl:value-of select="normalize-space(.)"/>
              <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </TD>
        </TR>
      </xsl:if>

      <xsl:if test="./@id!=''">
        <TR>
          <TD>Request Id</TD>
          <TD><xsl:value-of select="./@id"/></TD>
        </TR>
      </xsl:if>
      <xsl:if test="./purposeCode!=''">
        <TR>
          <TD>Purpose Code</TD>
          <TD><xsl:value-of select="normalize-space(./purposeCode)"/></TD>
        </TR>
      </xsl:if>
      <xsl:if test="./attention!=''">
        <TR>
          <TD>Attention</TD>
          <TD><xsl:value-of select="normalize-space(./attention)"/></TD>
        </TR>
      </xsl:if>
    </TABLE>
  </xsl:for-each>

  <xsl:if test="count(caveat)>0">
    <BR/>
    <TABLE BORDER="0" WIDTH="100%">
      <TR>
        <TD><B>The information in this rap sheet is provided subject 
        to the following caveats:</B></TD>
      </TR>
      <xsl:for-each select="caveat">
      <TR VALIGN="TOP">
        <TD WIDTH="100%">
          <xsl:value-of select="."/>
          <xsl:call-template name="format-attributes"/>
          <BR/><BR/>
        </TD>
      </TR>
      </xsl:for-each>
    </TABLE>
  </xsl:if>

<xsl:call-template name="navigation-bar"/>

</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                              person                               -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls formatting of information from the 
       person element.  It is called from the /rapSheet template.
-->

<xsl:template match="person">

  <H4>Subject Name(s)</H4>

  <B>
    <xsl:for-each select="personName">
      <xsl:sort select="concat(lastName, ',', firstName)"/>
      <DIV>
        <xsl:call-template name="format-personName"/>
      </DIV>
    </xsl:for-each>
  </B>

  <H4>Subject Description</H4>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>FBI Number</B></TD>
      <TD WIDTH="33%"><B>State Id Number</B></TD>
      <TD WIDTH="33%"><B>DOC Number</B></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/fbiNumber)>0">
            <xsl:for-each select="personDescription/fbiNumber">
              <DIV><xsl:value-of select="normalize-space(.)"/></DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/stateBureauIDNumber)>0">
            <xsl:for-each select="personDescription/stateBureauIDNumber">
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/personalIDNumber[@type='CorrectionalID'])>0">
            <xsl:for-each select="personDescription/personalIDNumber[@type='CorrectionalID']">
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes-no-type"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Social Security Number</B></TD>
      <TD WIDTH="33%"><B>Driver&apos;s License Number</B></TD>
      <TD WIDTH="33%"></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/ssn)>0">
            <xsl:for-each select="personDescription/ssn">
              <DIV><xsl:value-of select="normalize-space(.)"/></DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/dlNumber)>0">
            <xsl:for-each select="personDescription/dlNumber">
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD></TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Miscellaneous Numbers</B></TD>
      <TD WIDTH="66%"></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(personDescription/personalIDNumber[@type!='CorrectionalID'])>0">
        <TR>
          <TD><B>Number</B></TD>
          <TD><B>Type</B></TD>
        </TR>
        <xsl:for-each select="personDescription/personalIDNumber[@type!='CorrectionalID']">
          <TR>
            <TD>
              <xsl:value-of select="normalize-space(.)"/>
            </TD>
            <TD>
              <xsl:value-of select="normalize-space(@type)"/>
              <xsl:call-template name="format-attributes-no-type"/>
            </TD>
          </TR>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2">
          <xsl:text>Unknown/NA</xsl:text>
        </TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Sex</B></TD>
      <TD WIDTH="33%"><B>Race</B></TD>
      <TD WIDTH="33%"><B>Skin Tone</B></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/sex)>0">
            <xsl:for-each select="personDescription/sex">
              <DIV><xsl:value-of select="normalize-space(.)"/></DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/race)>0">
            <xsl:for-each select="personDescription/race">
              <DIV><xsl:value-of select="normalize-space(.)"/></DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/skinTone)>0">
            <xsl:for-each select="personDescription/skinTone">
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Height</B></TD>
      <TD WIDTH="33%"><B>Weight</B></TD>
      <TD WIDTH="33%"><B>Date of Birth</B></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/height)>0">
            <xsl:for-each select="personDescription/height">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:call-template name="format-height"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/weight)>0">
            <xsl:for-each select="personDescription/weight">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:call-template name="format-weight"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/birthDate)>0">
            <xsl:for-each select="personDescription/birthDate">
              <xsl:sort order="descending"/>
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Hair Color</B></TD>
      <TD WIDTH="33%"><B>Eye Color</B></TD>
      <TD WIDTH="33%"><B>Fingerprint Pattern</B></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/hairColor)>0">
            <xsl:for-each select="personDescription/hairColor">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/eyeColor)>0">
            <xsl:for-each select="personDescription/eyeColor">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/fingerprintPattern)>0">
            <xsl:for-each select="personDescription/fingerprintPattern">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD COLSPAN="2"><B>Scars, Marks, and Tattoos</B></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(personDescription/scarsMarksTattoos)>0">
        <TR>
          <TD WIDTH="34%"><B>Code</B></TD>
          <TD WIDTH="66%"><B>Description, Comments, and Images</B></TD>
        </TR>
        <xsl:for-each select="personDescription/scarsMarksTattoos">
          <xsl:sort select="@referenceDate" order="descending"/>
          <TR>
            <TD>
              <xsl:call-template name="format-code-source-date">
                <xsl:with-param name="node" 
                                select="./scarsMarksTattoosDescription"/>
                <xsl:with-param name="date" 
                                select="normalize-space(@referenceDate)"/>
              </xsl:call-template>
            </TD>
            <TD>
              <xsl:call-template name="format-smt-info"/>
            </TD>
          </TR>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2">Unknown/NA</TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Blood Type</B></TD>
      <TD WIDTH="66%"><B>Medical Condition</B></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/bloodType)>0">
            <xsl:for-each select="personDescription/bloodType">
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/medicalCondition)>0">
            <xsl:for-each select="personDescription/medicalCondition">
              <xsl:sort select="@referenceDate" order="descending"/>
              <xsl:call-template name="format-code-and-source"/>
              <xsl:if test=".!=''">
                <xsl:text> </xsl:text>
                <xsl:value-of select="normalize-space(.)"/>
              </xsl:if>
              <xsl:if test="./@referenceDate!=''">
                <xsl:text> (</xsl:text>
                <xsl:value-of select="normalize-space(./@referenceDate)"/>
                <xsl:text>)</xsl:text>
              </xsl:if>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Place of Birth</B></TD>
      <TD WIDTH="33%"><B>Citizenship</B></TD>
      <TD WIDTH="33%"><B>Ethnicity</B></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/birthPlace)>0">
            <xsl:for-each select="personDescription/birthPlace">
              <DIV>
                <xsl:value-of select="normalize-space(./birthPlaceData)"/>
              </DIV>
              <DIV>
                <xsl:call-template name="format-physicalLocation-1C">
                  <xsl:with-param name="pl" select="physicalLocation"/>
                </xsl:call-template>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/citizenship)>0">
            <xsl:for-each select="personDescription/citizenship">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/ethnicity)>0">
            <xsl:for-each select="personDescription/ethnicity">
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Marital Status</B></TD>
      <TD WIDTH="33%"><B>Religion</B></TD>
      <TD WIDTH="33%"><B></B></TD>
    </TR>
    <TR>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/maritalStatus)>0">
            <xsl:for-each select="personDescription/maritalStatus">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
        <xsl:choose>
          <xsl:when test="count(personDescription/religion)>0">
            <xsl:for-each select="personDescription/religion">
              <xsl:sort select="@referenceDate" order="descending"/>
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
                <xsl:call-template name="format-attributes"/>
              </DIV>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>Unknown/NA</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </TD>
      <TD>
      </TD>
    </TR>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Employment</B></TD>
      <TD WIDTH="66%"></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(employment)>0">
        <xsl:for-each select="employment">
          <xsl:sort select="./@referenceDate" order="descending"/>
          <xsl:if test="position()>1">
            <TR><TD COLSPAN="2"></TD></TR>
          </xsl:if>
          <xsl:if test="./@referenceDate!=''">
            <TR>
              <TD WIDTH="34%">
                <xsl:text>Employment as of</xsl:text>
              </TD>
              <TD WIDTH="66%">
                <xsl:value-of select="normalize-space(./@referenceDate)"/>
              </TD>
            </TR>
          </xsl:if>
          <xsl:if test="./occupation!=''">
            <TR>
              <TD WIDTH="34%">
                <xsl:text>Occupation</xsl:text>
              </TD>
              <TD WIDTH="66%">
                <xsl:value-of select="normalize-space(./occupation)"/>
              </TD>
            </TR>
          </xsl:if>
          <TR>
            <TD WIDTH="34%">
              <xsl:text>Employer</xsl:text>
            </TD>
            <TD WIDTH="66%">
              <xsl:value-of select="normalize-space(./employer)"/>
            </TD>
          </TR>
          <xsl:call-template name="format-physicalLocation-2C">
            <xsl:with-param name="pl" select="./physicalLocation"/>
          </xsl:call-template>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2"><xsl:text>Unknown/NA</xsl:text></TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD WIDTH="34%"><B>Residence</B></TD>
      <TD WIDTH="66%"></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(residence)>0">
        <xsl:for-each select="residence">
          <xsl:sort select="./@referenceDate" order="descending"/>
          <xsl:if test="position()>1">
            <TR><TD COLSPAN="2"></TD></TR>
          </xsl:if>
          <xsl:if test="./@referenceDate!=''">
            <TR>
              <TD WIDTH="34%">
                <xsl:text>Residence as of</xsl:text>
              </TD>
              <TD WIDTH="66%">
                <xsl:value-of select="normalize-space(./@referenceDate)"/>
              </TD>
            </TR>
          </xsl:if>
          <xsl:call-template name="format-physicalLocation-2C">
            <xsl:with-param name="pl" select="./physicalLocation"/>
          </xsl:call-template>
          <xsl:if test="count(telephone)>0">
            <TR>
              <TD WIDTH="34%">
                <xsl:text>Telephone</xsl:text>
              </TD>
              <TD WIDTH="66%">
                <xsl:for-each select="telephone">
                  <DIV>
                    <xsl:call-template name="format-telephone"/>
                  </DIV>
                </xsl:for-each>
              </TD>
            </TR>
          </xsl:if>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2"><xsl:text>Unknown/NA</xsl:text></TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD COLSPAN="2"><B>Fingerprint Images</B></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(fingerPrint)>0">
        <TR>
          <TD WIDTH="34%"><B>Type</B></TD>
          <TD WIDTH="66%"><B>Comments and Images</B></TD>
        </TR>
        <xsl:for-each select="fingerPrint">
          <xsl:sort select="@referenceDate" order="descending"/>
          <TR>
            <xsl:call-template name="format-fp-pp-p"/>
          </TR>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2">Unknown/NA</TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD COLSPAN="2"><B>Palmprint Images</B></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(palmPrint)>0">
        <TR>
          <TD WIDTH="34%"><B>Type</B></TD>
          <TD WIDTH="66%"><B>Comments and Images</B></TD>
        </TR>
        <xsl:for-each select="palmPrint">
          <xsl:sort select="@referenceDate" order="descending"/>
          <TR>
            <xsl:call-template name="format-fp-pp-p"/>
          </TR>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2">Unknown/NA</TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD COLSPAN="2"><B>Photo Images</B></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(photo)>0">
        <TR>
          <TD WIDTH="34%"><B>Type</B></TD>
          <TD WIDTH="66%"><B>Comments and Images</B></TD>
        </TR>
        <xsl:for-each select="photo">
          <xsl:sort select="@referenceDate" order="descending"/>
          <TR>
            <xsl:call-template name="format-fp-pp-p"/>
          </TR>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2">Unknown/NA</TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" WIDTH="100%">
    <TR>
      <TD COLSPAN="2"><B>DNA Data</B></TD>
    </TR>
    <xsl:choose>
      <xsl:when test="count(dna)>0">
        <TR>
          <TD WIDTH="34%"><B>Encoding Method</B></TD>
          <TD WIDTH="66%"><B>Data and Comments</B></TD>
        </TR>
        <xsl:for-each select="dna">
          <xsl:sort select="@referenceDate" order="descending"/>
          <TR>
            <TD>
              <xsl:choose>
                <xsl:when test="@contentEncoding!=''">
                  <xsl:value-of select="normalize-space(@contentEncoding)"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:text>Unknown Code</xsl:text>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:choose>
                <xsl:when test="@referenceDate!=''">
                  <xsl:text> (</xsl:text>
                  <xsl:value-of select="normalize-space(@referenceDate)"/>
                  <xsl:text>)</xsl:text>
                </xsl:when>
                <xsl:otherwise>
                </xsl:otherwise>
              </xsl:choose>
            </TD>
            <TD>
              <xsl:choose>
                <xsl:when test="count(dnaLocus)>0">
                    <xsl:text>DNA locus data table follows </xsl:text>
                    <xsl:call-template name="format-agency-list"/>
                    <TABLE BORDER="0" WIDTH="100%">
                      <TR>
                        <TD WIDTH="100"><B>Locus</B></TD><TD><B>Value</B></TD>
                        <TD WIDTH="100"><B>Locus</B></TD><TD><B>Value</B></TD>
                      </TR>
                      <xsl:variable name="data-count" 
                                    select="count(dnaLocus)"/>
                      <xsl:for-each select="dnaLocus">
                        <xsl:if test="(position() mod 2)=1">
                          <TR>
                            <TD><xsl:value-of select="./@type"/></TD>
                            <TD>
                              <xsl:for-each select="./dnaLocusValue">
                                <xsl:if test="position()>1">
                                  <xsl:text>, </xsl:text>
                                </xsl:if>
                                <xsl:value-of select="normalize-space(.)"/>
                              </xsl:for-each>
                            </TD>
                            <xsl:choose>
                              <xsl:when test="(position()+1)>$data-count">
                                <TD></TD><TD></TD>
                              </xsl:when>
                              <xsl:otherwise>
                                <TD><xsl:value-of select="following::dnaLocus[1]/@type"/></TD>
                                <TD>
                                  <xsl:for-each select="following::dnaLocus[1]/dnaLocusValue">
                                    <xsl:if test="position()>1">
                                      <xsl:text>, </xsl:text>
                                    </xsl:if>
                                    <xsl:value-of select="normalize-space(.)"/>
                                  </xsl:for-each>
                                </TD>
                              </xsl:otherwise>
                            </xsl:choose>
                          </TR>
                        </xsl:if>
                      </xsl:for-each>
                    </TABLE>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:text>Contact agency for data </xsl:text>
                  <xsl:call-template name="format-agency-list"/>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:for-each select="comment">
                <DIV>
                  <xsl:value-of select="normalize-space(.)"/>
                </DIV>
              </xsl:for-each>
            </TD>
          </TR>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <TR><TD COLSPAN="2">Unknown/NA</TD></TR>
      </xsl:otherwise>
    </xsl:choose>
  </TABLE>

  <BR/>

  <TABLE BORDER="0" CELLPADDING="0" WIDTH="100%">
    <TR>
      <TD COLSPAN="2"><B>Caution Information</B></TD>
    </TR>
    <xsl:if test="firearmSalesDisqualified!=''">
      <TR>
        <TD WIDTH="34%">Firearms Disqualified</TD>
        <TD WIDTH="66%">
          <xsl:variable name="d" 
               select="normalize-space(./firearmSalesDisqualified)"/>
          <xsl:value-of select="$d"/>
          <xsl:text> - </xsl:text>
          <xsl:choose>
            <xsl:when test="$d='F'">
              <xsl:text>Felony Conviction</xsl:text>
            </xsl:when>
            <xsl:when test="$d='M'">
              <xsl:text>Misdemeanor Conviction</xsl:text>
            </xsl:when>
            <xsl:when test="$d='D'">
              <xsl:text>Disqualified</xsl:text>
            </xsl:when>
            <xsl:when test="$d='C'">
              <xsl:text>Cleared</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>Status unknown or pending</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </TD>
      </TR>
    </xsl:if>
    <xsl:for-each select="./caution">
       <xsl:sort select="./@referenceDate" order="descending"/>
       <TR>
         <TD WIDTH="34%">Caution</TD>
         <TD WIDTH="66%">
           <xsl:value-of select="normalize-space(.)"/>
           <xsl:call-template name="format-attributes"/>
         </TD>
       </TR>
    </xsl:for-each>
    <xsl:for-each select="./offenderNotice">
       <xsl:sort select="./@referenceDate" order="descending"/>
       <TR>
         <TD WIDTH="34%">Notice</TD>
         <TD WIDTH="66%">
           <xsl:value-of select="normalize-space(.)"/>
           <xsl:call-template name="format-attributes"/>
         </TD>
       </TR>
    </xsl:for-each>
    <xsl:for-each select="./comment">
       <xsl:sort select="./@referenceDate" order="descending"/>
       <TR>
         <TD WIDTH="34%">Comment(s)</TD>
         <TD WIDTH="66%">
           <xsl:value-of select="normalize-space(.)"/>
           <xsl:call-template name="format-attributes"/>
         </TD>
       </TR>
    </xsl:for-each>
  </TABLE>


<xsl:call-template name="navigation-bar"/>

</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                           cycle                             -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls formatting of information from cycle
       elements.  It is called from the /rapSheet template.
-->

<xsl:template name="cycle">

  <TABLE BORDER="0" WIDTH="100%">
    <xsl:choose>
    <xsl:when test="count(cycle)>0">
      <xsl:for-each select="cycle">
        <xsl:sort select="earliestDate"/>
        <xsl:variable name="cycle-number"
                      select="format-number(position(), '000')"/>
        <TR><TD COLSPAN="2"><BR/></TD></TR>

        <TR>
          <TD COLSPAN="2" ALIGN="CENTER" STYLE="borde solid thin"
              BGCOLOR="#AACCFF">
            <B>
              <xsl:text>Cycle </xsl:text>
              <xsl:value-of select="$cycle-number"/>
            </B>
          </TD>
        </TR>

        <TR><TD COLSPAN="2"><BR/></TD></TR>

        <xsl:if test="count(cycleTrackingNumber)>0">
          <TR>
            <TD><B>Tracking Number</B></TD>
            <TD>
              <xsl:value-of select="normalize-space(cycleTrackingNumber)"/>
            </TD>
          </TR>
        </xsl:if>

        <xsl:if test="count(earliestDate)>0">
          <TR>
            <TD><B>Earliest Event Date</B></TD>
            <TD>
              <xsl:value-of select="normalize-space(earliestDate)"/>
            </TD>
          </TR>
        </xsl:if>

        <xsl:choose>
          <xsl:when test="count(arrest)>0">
            <TR><TD COLSPAN="2"><HR/></TD></TR>
            <xsl:call-template name="arrest">
              <xsl:with-param name="cycle-number" select="$cycle-number"/>
            </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
            <TR><TD COLSPAN="2"><HR/></TD></TR>
            <TR>
              <TD><B>Arrest</B></TD>
              <TD>No data supplied</TD>
            </TR>
          </xsl:otherwise>
        </xsl:choose>

        <xsl:choose>
          <xsl:when test="count(prosecutorDisposition)>0">
            <xsl:for-each select="prosecutorDisposition">
              <TR><TD COLSPAN="2"><HR/></TD></TR>
              <xsl:call-template name="prosecutorDisposition">
                <xsl:with-param name="cycle-number" select="$cycle-number"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <TR><TD COLSPAN="2"><HR/></TD></TR>
            <TR>
              <TD><B>Prosecutor Disposition</B></TD>
              <TD>No data supplied</TD>
            </TR>
          </xsl:otherwise>
        </xsl:choose>

        <xsl:choose>
          <xsl:when test="count(courtDisposition)>0">
            <xsl:for-each select="courtDisposition">
              <TR><TD COLSPAN="2"><HR/></TD></TR>
              <xsl:call-template name="courtDisposition">
                <xsl:with-param name="cycle-number" select="$cycle-number"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <TR><TD COLSPAN="2"><HR/></TD></TR>
            <TR>
              <TD><B>Court Disposition</B></TD>
              <TD>No data supplied</TD>
            </TR>
          </xsl:otherwise>
        </xsl:choose>

        <xsl:choose>
          <xsl:when test="count(sentencing)>0">
            <xsl:for-each select="sentencing">
              <TR><TD COLSPAN="2"><HR/></TD></TR>
              <xsl:call-template name="sentencing">
                <xsl:with-param name="cycle-number" select="$cycle-number"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <TR><TD COLSPAN="2"><HR/></TD></TR>
            <TR>
              <TD><B>Sentencing</B></TD>
              <TD>No data supplied</TD>
            </TR>
          </xsl:otherwise>
        </xsl:choose>

        <xsl:choose>
          <xsl:when test="count(corrections)>0">
            <xsl:for-each select="corrections">
              <TR><TD COLSPAN="2"><HR/></TD></TR>
              <xsl:call-template name="corrections">
                <xsl:with-param name="cycle-number" select="$cycle-number"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <TR><TD COLSPAN="2"><HR/></TD></TR>
            <TR>
              <TD><B>Corrections</B></TD>
              <TD>No data supplied</TD>
            </TR>
          </xsl:otherwise>
        </xsl:choose>

      </xsl:for-each>  <!--  cycle element  -->
    </xsl:when>
    <xsl:otherwise>
      <TR>
        <TD COLSPAN="2">
          <B><xsl:text>No cycles in rap sheet. </xsl:text></B>
          <xsl:text>Contact agency. </xsl:text>
        </TD>
      </TR>
    </xsl:otherwise>
    </xsl:choose>
  </TABLE>

<xsl:call-template name="navigation-bar"/>

</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                              arrest                               -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formats arrest information  -->

<xsl:template name="arrest">
  <xsl:param name="cycle-number"/>

  <TR>
    <TD WIDTH="34%"><B>Arrest </B></TD>
    <TD WIDTH="66%">
      <xsl:text>(Cycle </xsl:text>
      <xsl:value-of select="$cycle-number"/>
      <xsl:text>)</xsl:text>
    </TD>
  </TR>

  <TR>
    <TD WIDTH="34%"><B>Arrest Date</B></TD>
    <TD WIDTH="66%">
      <xsl:value-of select="normalize-space(arrest/arrestDate)"/>
    </TD>
  </TR>

  <xsl:if test="count(arrest/arrestCaseNumber)>0">
    <TR>
      <TD><B>Arrest Case Number</B></TD>
      <TD>
        <xsl:value-of select="normalize-space(arrest/arrestCaseNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(arrest/agency)>0">
    <TR>
      <TD><B>Arresting Agency</B></TD>
      <TD>
        <xsl:call-template name="format-agency-list-no-parens">
          <xsl:with-param name="node" select="arrest"/>
        </xsl:call-template>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(arrest/personName)>0">
  <TR>
    <TD><B>Subject Name(s)</B></TD>
    <TD>
      <xsl:for-each select="arrest/personName">
        <xsl:sort select="concat(lastName, ',', firstName)"/>
        <DIV>
          <xsl:call-template name="format-personName"/>
        </DIV>
      </xsl:for-each>
    </TD>
  </TR>
  </xsl:if>

  <xsl:if test="count(arrest/personalIDNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Offender ID Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(arrest/personalIDNumber)"/>
        <xsl:call-template name="format-attributes-no-type">
          <xsl:with-param name="node" select="arrest/personalIDNumber"/>
        </xsl:call-template>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(arrest/arrestType)>0">
    <TR>
      <TD ALIGN="RIGHT">Arrest Type</TD>
      <TD>
        <xsl:value-of select="normalize-space(arrest/arrestType)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(arrest/comment)>0">
    <TR>
      <TD ALIGN="RIGHT">
        <xsl:text>Comment(s)</xsl:text>
      </TD>
      <TD>
        <xsl:for-each select="arrest/comment">
          <DIV>
            <xsl:value-of select="normalize-space(.)"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>

  <xsl:for-each select="arrest/charge">
    <xsl:call-template name="format-charge"/>
  </xsl:for-each>

</xsl:template>  <!-- arrest -->


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                     prosecutorDisposition                         -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formats prosecutor disposition information  -->

<xsl:template name="prosecutorDisposition">
  <xsl:param name="cycle-number"/>

  <TR>
    <TD WIDTH="34%"><B>Prosecutor Disposition</B></TD>
    <TD WIDTH="66%">
      <xsl:text>(Cycle </xsl:text>
      <xsl:value-of select="$cycle-number"/>
      <xsl:text>)</xsl:text>
      <xsl:value-of select="cycleTrackingNumber"/>
    </TD>
  </TR>

  <xsl:if test="count(prosecutorCaseNumber)>0">
    <TR>
      <TD><B>Prosecutor Case Number</B></TD>
      <TD>
        <xsl:value-of select="normalize-space(prosecutorCaseNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(agency)>0">
    <TR>
      <TD><B>Prosecutor Agency</B></TD>
      <TD>
        <xsl:call-template name="format-agency-list-no-parens"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(personName)>0">
  <TR>
    <TD><B>Subject Name(s)</B></TD>
    <TD>
      <xsl:for-each select="personName">
        <xsl:sort select="concat(lastName, ',', firstName)"/>
        <DIV>
          <xsl:call-template name="format-personName"/>
        </DIV>
      </xsl:for-each>
    </TD>
  </TR>
  </xsl:if>

  <xsl:for-each select="charge">
    <xsl:call-template name="format-charge"/>
  </xsl:for-each>

</xsl:template>  <!-- prosecutorDisposition -->


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        courtDisposition                           -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formats court disposition information  -->

<xsl:template name="courtDisposition">
  <xsl:param name="cycle-number"/>

  <TR>
    <TD WIDTH="34%"><B>Court Disposition</B></TD>
    <TD WIDTH="66%">
      <xsl:text>(Cycle </xsl:text>
      <xsl:value-of select="$cycle-number"/>
      <xsl:text>)</xsl:text>
      <xsl:value-of select="cycleTrackingNumber"/>
    </TD>
  </TR>

  <xsl:if test="count(courtCaseNumber)>0">
    <TR>
      <TD><B>Court Case Number</B></TD>
      <TD>
        <xsl:value-of select="normalize-space(courtCaseNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(agency)>0">
    <TR>
      <TD><B>Court Agency</B></TD>
      <TD>
        <xsl:call-template name="format-agency-list-no-parens"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(personName)>0">
  <TR>
    <TD><B>Subject Name(s)</B></TD>
    <TD>
      <xsl:for-each select="personName">
        <xsl:sort select="concat(lastName, ',', firstName)"/>
        <DIV>
          <xsl:call-template name="format-personName"/>
        </DIV>
      </xsl:for-each>
    </TD>
  </TR>
  </xsl:if>

  <xsl:for-each select="charge">
    <xsl:call-template name="format-charge"/>
  </xsl:for-each>

</xsl:template>  <!-- courtDisposition -->


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                           sentencing                              -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formats sentencing information  -->

<xsl:template name="sentencing">
  <xsl:param name="cycle-number"/>

  <TR>
    <TD WIDTH="34%"><B>Sentencing</B></TD>
    <TD WIDTH="66%">
      <xsl:text>(Cycle </xsl:text>
      <xsl:value-of select="$cycle-number"/>
      <xsl:text>)</xsl:text>
    </TD>
  </TR>

  <xsl:if test="count(agency)>0">
    <TR>
      <TD><B>Sentencing Agency</B></TD>
      <TD>
        <xsl:call-template name="format-agency-list-no-parens"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(courtCaseNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Court Case Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(courtCaseNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(chargeNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Charge Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(chargeNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(chargeSequenceNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Charge Sequence Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(chargeSequenceNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(chargeTrackingNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Charge Tracking Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(chargeTrackingNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(sentence)>0">
    <TR>
      <TD ALIGN="RIGHT">Sentence</TD>
      <TD>
        <xsl:for-each select="sentence">
          <DIV>
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:call-template name="format-attributes"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(comment)>0">
    <TR>
      <TD ALIGN="RIGHT">
        <xsl:text>Comment(s)</xsl:text>
      </TD>
      <TD>
        <xsl:for-each select="comment">
          <DIV>
            <xsl:value-of select="normalize-space(.)"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>

</xsl:template>  <!-- sentencing -->


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                           corrections                             -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formats corrections information  -->

<xsl:template name="corrections">
  <xsl:param name="cycle-number"/>

  <TR>
    <TD WIDTH="34%"><B>Corrections</B></TD>
    <TD WIDTH="66%">
      <xsl:text>(Cycle </xsl:text>
      <xsl:value-of select="$cycle-number"/>
      <xsl:text>)</xsl:text>
    </TD>
  </TR>

  <xsl:if test="count(agency)>0">
    <TR>
      <TD><B>Corrections Agency</B></TD>
      <TD>
        <xsl:call-template name="format-agency-list-no-parens"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(personName)>0">
  <TR>
    <TD><B>Subject Name(s)</B></TD>
    <TD>
      <xsl:for-each select="personName">
        <xsl:sort select="concat(lastName, ',', firstName)"/>
        <DIV>
          <xsl:call-template name="format-personName"/>
        </DIV>
      </xsl:for-each>
    </TD>
  </TR>
  </xsl:if>

  <xsl:if test="count(personalIDNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Correctional Id Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(personalIDNumber)"/>
        <xsl:call-template name="format-attributes-no-type">
          <xsl:with-param name="node" select="personalIDNumber"/>
        </xsl:call-template>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(courtCaseNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Court Case Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(courtCaseNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(correctionAction)>0">
    <TR>
      <TD ALIGN="RIGHT">Correction Action</TD>
      <TD>
        <xsl:for-each select="correctionAction">
          <DIV>
            <xsl:value-of select="normalize-space(.)"/>
            <xsl:call-template name="format-attributes"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(comment)>0">
    <TR>
      <TD ALIGN="RIGHT">
        <xsl:text>Comment(s)</xsl:text>
      </TD>
      <TD>
        <xsl:for-each select="comment">
          <DIV>
            <xsl:value-of select="normalize-space(.)"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>

</xsl:template>  <!-- corrections -->


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                           agencyIndex                             -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   This template controls formatting of information from index
       elements.  It is called from the /rapSheet template.
-->

<xsl:template match="agencyIndex">

  <TABLE BORDER="0" WIDTH="100%">
    <xsl:for-each select="agencyInformation">
      <xsl:if test="position()>1">
        <TR>
          <TD COLSPAN="2"><HR/></TD>
        </TR>
      </xsl:if>

      <TR>
        <TD>Agency</TD>
        <TD>
          <xsl:call-template name="format-agency-list-no-parens"/>
        </TD>
      </TR>

      <xsl:if test="(count(contactPerson)+count(department))>0">
        <TR>
          <TD WIDTH="34%">Contact</TD>
          <TD WIDTH="66%">
            <xsl:if test="normalize-space(department)!=''">
              <DIV>
                <xsl:value-of select="normalize-space(./department)"/>
                <xsl:text> Department</xsl:text>
              </DIV>
            </xsl:if>
            <xsl:for-each select="contactPerson">
              <DIV>
                <xsl:value-of select="normalize-space(.)"/>
              </DIV>
            </xsl:for-each>
          </TD>
        </TR>
      </xsl:if>

      <xsl:if test="count(telephone)>0">
        <TR>
          <TD>
            <xsl:text>Agency Telephone</xsl:text>
          </TD>
          <TD>
            <xsl:for-each select="telephone">
              <DIV>
                <xsl:call-template name="format-telephone"/>
              </DIV>
            </xsl:for-each>
          </TD>
        </TR>
      </xsl:if>

      <xsl:if test="count(fax)>0">
        <TR>
          <TD>
            <xsl:text>Agency Facsimile</xsl:text>
          </TD>
          <TD>
            <xsl:for-each select="fax">
              <DIV>
                <xsl:call-template name="format-telephone">
                  <xsl:with-param name="node" select="telephone"/>
                </xsl:call-template>
              </DIV>
            </xsl:for-each>
          </TD>
        </TR>
      </xsl:if>

      <xsl:if test="count(email)>0">
        <TR>
          <TD>Agency Email Address</TD>
          <TD>
           <xsl:for-each select="email">
             <DIV>
               <xsl:value-of select="normalize-space(.)"/>
             </DIV>
           </xsl:for-each>
         </TD>
        </TR>
      </xsl:if>

      <xsl:if test="count(physicalLocation)>0">
        <TR>
          <xsl:call-template name="format-physicalLocation-2C">
            <xsl:with-param name="pl" select="./physicalLocation"/>
          </xsl:call-template>
        </TR>
      </xsl:if>

    </xsl:for-each>
  </TABLE>

  <xsl:call-template name="navigation-bar"/>

</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        format-personName                         -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formatting of person names.   -->

<xsl:template name="format-personName">
  <xsl:param name="subject" select="."/>
  <xsl:value-of select="$subject/lastName"/>
  <xsl:if test="($subject/namePrefix!='') or ($subject/firstName!='') or ($subject/middleName!='') or ($subject/nameSuffix!='')">
    <xsl:text>,</xsl:text>
  </xsl:if>
  <xsl:for-each select="$subject/namePrefix">
    <xsl:text> </xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
  </xsl:for-each>
  <xsl:if test="$subject/firstName!=''">
    <xsl:text> </xsl:text>
    <xsl:value-of select="normalize-space($subject/firstName)"/>
  </xsl:if>
  <xsl:for-each select="$subject/middleName">
    <xsl:text> </xsl:text>
    <xsl:value-of select="normalize-space(.)"/>
  </xsl:for-each>
  <xsl:for-each select="$subject/nameSuffix">
    <xsl:text> </xsl:text> 
    <xsl:value-of select="normalize-space(.)"/>
  </xsl:for-each>
  <xsl:if test="$subject/@type!=''">
    <xsl:if test="$subject/@type!='Primary'">
       <xsl:text> (</xsl:text>
       <xsl:value-of select="$subject/@type"/>
       <xsl:text>)</xsl:text>
    </xsl:if>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        prepend-attribute                          -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Prepend an attribute to a list   -->

<xsl:template name="prepend-attribute">
  <xsl:param name="attr"/>
  <xsl:param name="list"/>
  <xsl:variable name="result">
    <xsl:choose>
    <xsl:when test="$list!=''">
      <xsl:choose>
        <xsl:when test="$attr!=''">
          <xsl:value-of select="$attr"/>; <xsl:value-of select="$list"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$list"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$attr"/>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:value-of select="$result"/>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        format-attributes                          -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formatting of a standard set of attributes   -->

<xsl:template name="format-attributes">
  <xsl:param name="node" select="."/>
  <xsl:variable name="r45">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@codeValue"/>
      <xsl:with-param name="list" select="$node/@type"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r345">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@codeSource"/>
      <xsl:with-param name="list" select="$r45"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r2345">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@referenceDate"/>
      <xsl:with-param name="list" select="$r345"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r12345">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@issuingAuthority"/>
      <xsl:with-param name="list" select="$r2345"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:if test="$r12345!=''">
    <xsl:text> (</xsl:text>
    <xsl:value-of select="$r12345"/>
    <xsl:text>)</xsl:text>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                    format-attributes-no-type                      -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formatting of a standard set of attributes (but no type)   -->

<xsl:template name="format-attributes-no-type">
  <xsl:param name="node" select="."/>
  <xsl:variable name="r34">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@codeSource"/>
      <xsl:with-param name="list" select="$node/@codeValue"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r234">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@referenceDate"/>
      <xsl:with-param name="list" select="$r34"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r1234">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@issuingAuthority"/>
      <xsl:with-param name="list" select="$r234"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:if test="$r1234!=''">
    <xsl:text> (</xsl:text>
    <xsl:value-of select="$r1234"/>
    <xsl:text>)</xsl:text>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                     format-code-source-date                       -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formatting of a standard set of attributes (but no type)   -->

<xsl:template name="format-code-source-date">
  <xsl:param name="node" select="."/>
  <xsl:param name="date" select="./@referenceDate"/>
  <xsl:variable name="code-source">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/@codeSource"/>
      <xsl:with-param name="list" select="$date"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="normalize-space($node/@codeValue)!=''">
      <xsl:value-of select="normalize-space($node/@codeValue)"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>Unknown Code</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:if test="$code-source!=''">
    <xsl:text> (</xsl:text>
    <xsl:value-of select="$code-source"/>
    <xsl:text>)</xsl:text>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                     format-code-and-source                        -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Another formatting for codeValue and codeSource attributes  -->

<xsl:template name="format-code-and-source">
  <xsl:param name="node" select="."/>
  <xsl:choose>
    <xsl:when test="($node/@codeValue!='') or ($node/@codeSource!='')">
      <xsl:choose>
        <xsl:when test="$node/@codeValue!=''">
          <xsl:value-of select="normalize-space($node/@codeValue)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>Code Unknown</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text> (</xsl:text>
      <xsl:choose>
        <xsl:when test="$node/@codeSource!=''">
          <xsl:value-of select="$node/@codeSource"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>Source Unknown</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>)</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>Code Unknown/NA</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                          format-height                            -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for height  -->

<xsl:template name="format-height">
  <xsl:param name="height" select="."/>
  <xsl:choose>
    <xsl:when test="$height!=''">
      <xsl:choose>
        <xsl:when test="$height/@units='Inches'">
          <xsl:value-of select="floor(($height) div 12)"/>
          <xsl:text>'</xsl:text>
          <xsl:value-of select="($height) mod 12"/>
          <xsl:text>"</xsl:text>
        </xsl:when>
        <xsl:when test="$height/@units='FeetInches'">
          <xsl:value-of select="floor(($height) div 100)"/>
          <xsl:text>'</xsl:text>
          <xsl:value-of select="($height) mod 100"/>
          <xsl:text>"</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$height"/>
         <xsl:text> </xsl:text>
         <xsl:value-of select="$height/@units"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="format-attributes"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>Unknown/NA</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                          format-weight                            -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for weight  -->

<xsl:template name="format-weight">
  <xsl:param name="weight" select="."/>
  <xsl:choose>
    <xsl:when test="$weight!=''">
      <xsl:value-of select="normalize-space($weight)"/>
      <xsl:if test="$weight/@units!=''">
         <xsl:text> </xsl:text>
         <xsl:value-of select="$weight/@units"/>
      </xsl:if>
      <xsl:call-template name="format-attributes"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>Unknown/NA</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                   format-agency-list-no-parens                    -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for agency information  -->

<xsl:template name="format-agency-list-no-parens">
  <xsl:param name="node" select="."/>
  <xsl:param name="date"/>
  <xsl:variable name="ori" select="normalize-space($node/agency/ori)"/>
  <xsl:variable name="r45">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$ori"/>
      <xsl:with-param name="list" select="$date"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r345">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" 
                      select="$node/agency/entityAbbreviatedName"/>
      <xsl:with-param name="list" select="$r45"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r2345">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/agency/entityName"/>
      <xsl:with-param name="list" select="$r345"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r12345">
    <xsl:call-template name="prepend-attribute">
      <xsl:with-param name="attr" select="$node/agency/entityAcronym"/>
      <xsl:with-param name="list" select="$r2345"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:value-of select="$r12345"/>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                       format-agency-list                          -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for agency information  -->

<xsl:template name="format-agency-list">
  <xsl:param name="node" select="."/>
  <xsl:param name="date"/>
  <xsl:variable name="agency-list">
    <xsl:call-template name="format-agency-list-no-parens">
      <xsl:with-param name="node" select="$node"/>
      <xsl:with-param name="date" select="$date"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:if test="$agency-list!=''">
    <xsl:text> (</xsl:text>
    <xsl:value-of select="$agency-list"/>
    <xsl:text>)</xsl:text>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                          format-image                             -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for image information  -->

<xsl:template name="format-image">
  <xsl:param name="node" select="."/>
  <xsl:variable name="data" select="normalize-space($node/imageData)"/>
  <DIV>
  <xsl:choose>
    <xsl:when test="$node/imageData/@contentEncoding!=''">
      <A HREF="a-generated-link"><xsl:text>Embedded Image</xsl:text></A>
    </xsl:when>
    <xsl:when test="$node/imageData/@href!=''">
      <xsl:choose>
        <xsl:when test="$data!=''">
          <A HREF="{$node/imageData/@href}">
            <xsl:value-of select="$data"/>
          </A>
        </xsl:when>
        <xsl:otherwise>
          <A HREF="{$node/imageData/@href}">
            <xsl:value-of select="$node/imageData/@href"/>
          </A>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:when test="starts-with(translate($data, 'htp', 'HTP'), 'HTTP')">
      <A HREF="{$data}"><xsl:value-of select="$data"/></A>
    </xsl:when>
    <xsl:when test="$data=''">
      <xsl:text>Contact agency for image</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$data"/>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:call-template name="format-agency-list">
    <xsl:with-param name="node" select="$node"/>
  </xsl:call-template>
  </DIV>
  <xsl:for-each select="$node/comment">
    <DIV>
      <xsl:value-of select="normalize-space(.)"/>
    </DIV>
  </xsl:for-each>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        format-smt-image                           -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for image information  -->

<xsl:template name="format-smt-image">
  <xsl:param name="node" select="."/>
  <xsl:variable name="data" select="normalize-space($node/imageData)"/>
  <DIV>
  <xsl:choose>
    <xsl:when test="$node/imageData/@contentEncoding!=''">
      <A HREF="a-generated-link"><xsl:text>Embedded Image</xsl:text></A>
    </xsl:when>
    <xsl:when test="$node/imageData/@href!=''">
      <xsl:choose>
        <xsl:when test="$data!=''">
          <A HREF="{$node/imageData/@href}">
            <xsl:value-of select="$data"/>
          </A>
        </xsl:when>
        <xsl:otherwise>
          <A HREF="{$node/imageData/@href}">
            <xsl:value-of select="$node/imageData/@href"/>
          </A>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:when test="starts-with(translate($data, 'htp', 'HTP'), 'HTTP')">
      <A HREF="{$data}"><xsl:value-of select="$data"/></A>
    </xsl:when>
    <xsl:when test="$data=''">
      <xsl:text>Contact agency for image</xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$data"/>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:call-template name="format-agency-list">
    <xsl:with-param name="node" select="$node"/>
    <xsl:with-param name="date" 
         select="normalize-space($node/@referenceDate)"/>
  </xsl:call-template>
  </DIV>
  <xsl:for-each select="$node/comment">
    <DIV>
      <xsl:value-of select="normalize-space(.)"/>
    </DIV>
  </xsl:for-each>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        format-smt-info                            -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for most smt information  -->

<xsl:template name="format-smt-info">
  <xsl:param name="node" select="."/>
  <DIV>
    <xsl:if test="$node/scarsMarksTattoosDescription!=''">
      <xsl:value-of select="normalize-space($node/scarsMarksTattoosDescription)"/>
    </xsl:if>
    <xsl:call-template name="format-agency-list"/>
  </DIV>
  <xsl:choose>
    <xsl:when test="count($node/image)>0">
      <xsl:for-each select="$node/image">
        <xsl:sort select="@referenceDate" order="descending"/>
        <DIV>
          <xsl:call-template name="format-smt-image">
            <xsl:with-param name="node" select="."/>
          </xsl:call-template>
        </DIV>
      </xsl:for-each>
    </xsl:when>
    <xsl:otherwise>
      <xsl:text>Contact agency for image</xsl:text>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        format-fp-pp-p                             -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for fingerPrint, palmPrint, and photo  -->

<xsl:template name="format-fp-pp-p">
  <xsl:param name="node" select="."/>
  <TD>
    <xsl:choose>
      <xsl:when test="$node/@type!=''">
        <xsl:value-of select="normalize-space($node/@type)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>Unknown Code</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="$node/@referenceDate!=''">
        <xsl:text> (</xsl:text>
        <xsl:value-of select="normalize-space($node/@referenceDate)"/>
        <xsl:text>)</xsl:text>
      </xsl:when>
      <xsl:otherwise>
      </xsl:otherwise>
    </xsl:choose>
  </TD>
  <TD>
    <xsl:call-template name="format-image">
      <xsl:with-param name="node" select="$node"/>
    </xsl:call-template>
  </TD>

</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                   format-physicalLocation-1C                      -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for physicalLocation in one column  -->

<xsl:template name="format-physicalLocation-1C">
  <xsl:param name="pl" select="."/>
  <xsl:if test="$pl/locationType!=''">
    <DIV>
    <xsl:text>Location Type </xsl:text>
    <xsl:value-of select="normalize-space($pl/locationType)"/>
    </DIV>
  </xsl:if>
  <xsl:if test="$pl/location!=''">
    <xsl:call-template name="format-location">
      <xsl:with-param name="location" select="$pl/location"/>
    </xsl:call-template>
  </xsl:if>
  <xsl:if test="($pl/location!='') or ($pl/postalAddress!='')">
    <DIV/>
  </xsl:if>
  <xsl:if test="$pl/postalAddress!=''">
    <DIV>
    <xsl:text>Mailing Address </xsl:text>
    </DIV>
    <DIV>
    <xsl:call-template name="format-postalAddress">
      <xsl:with-param name="location" select="$pl/postalAddress"/>
    </xsl:call-template>
    </DIV>
  </xsl:if>
  <xsl:if test="$pl/relatedLocation!=''">
    <DIV>
    <xsl:text>Related Location </xsl:text>
    </DIV>
    <DIV>
    <xsl:value-of select="normalize-space($pl/relatedLocation)"/>
    </DIV>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                   format-physicalLocation-2C                      -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for physicalLocation in two columns  -->

<xsl:template name="format-physicalLocation-2C">
  <xsl:param name="pl" select="."/>
  <xsl:if test="$pl/locationType!=''">
    <TR>
      <TD WIDTH="34%">Location Type</TD>
      <TD WIDTH="66%">
        <xsl:value-of select="normalize-space($pl/locationType)"/>
      </TD>
    </TR>
  </xsl:if>
  <xsl:if test="$pl/location!=''">
    <TR>
      <TD WIDTH="34%">Address</TD>
      <TD WIDTH="66%">
        <xsl:call-template name="format-location">
          <xsl:with-param name="location" select="$pl/location"/>
        </xsl:call-template>
      </TD>
    </TR>
  </xsl:if>
  <xsl:if test="$pl/postalAddress!=''">
    <TR>
      <TD WIDTH="34%">Mailing Address</TD>
      <TD WIDTH="66%">
        <xsl:call-template name="format-postalAddress">
          <xsl:with-param name="location" select="$pl/postalAddress"/>
        </xsl:call-template>
      </TD>
    </TR>
  </xsl:if>
  <xsl:if test="$pl/relatedLocation!=''">
    <TR>
    <TD WIDTH="34%">Related Location</TD>
    <TD WIDTH="66%">
      <xsl:value-of select="normalize-space($pl/relatedLocation)"/>
    </TD>
    </TR>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                         format-location                           -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for location within physicalLocation  -->

<xsl:template name="format-location">
  <xsl:param name="location" select="./location"/>
  <xsl:for-each select="$location/addressLine">
    <DIV>
    <xsl:value-of select="normalize-space(.)"/>
    </DIV>
  </xsl:for-each>
  <xsl:if test="($location/streetNumber!='') or ($location/streetName!='')">
    <DIV>
    <xsl:if test="$location/streetNumber!=''">
      <xsl:value-of select="normalize-space($location/streetNumber)"/>
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:if test="$location/streetDirection!=''">
      <xsl:value-of select="normalize-space($location/streetDirection)"/>
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:if test="$location/streetName!=''">
      <xsl:value-of select="normalize-space($location/streetName)"/>
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:if test="$location/streetType!=''">
      <xsl:value-of select="normalize-space($location/streetType)"/>
    </xsl:if>
    </DIV>
  </xsl:if>
  <xsl:if test="($location/buildingName!='') or ($location/apartmentNumber!='') or ($location/suite!='')">
    <DIV>
    <xsl:if test="$location/buildingName!=''">
      <xsl:value-of select="normalize-space($location/buildingName)"/>
      <xsl:text> Building </xsl:text>
    </xsl:if>
    <xsl:if test="$location/apartmentNumber!=''">
      <xsl:text>Apartment </xsl:text>
      <xsl:value-of select="normalize-space($location/apartmentNumber)"/>
      <xsl:text> </xsl:text>
    </xsl:if>
    <xsl:if test="$location/suite!=''">
      <xsl:text>Suite </xsl:text>
      <xsl:value-of select="normalize-space($location/suite)"/>
    </xsl:if>
    </DIV>
  </xsl:if>
  <xsl:if test="$location/postOfficeBox!=''">
    <DIV>
    <xsl:text>PO Box </xsl:text>
    <xsl:value-of select="normalize-space($location/postOfficeBox)"/>
    </DIV>
  </xsl:if>
  <xsl:if test="$location/privateMailBox!=''">
    <DIV>
    <xsl:text>MSC </xsl:text>
    <xsl:value-of select="normalize-space($location/privateMailBox)"/>
    </DIV>
  </xsl:if>
  <xsl:if test="$location/county!=''">
    <DIV>
    <xsl:value-of select="normalize-space($location/county)"/>
    <xsl:text> County</xsl:text>
    </DIV>
  </xsl:if>
  <xsl:if test="($location/city!='') or ($location/state!='') or ($location/postalCode!='') or ($location/country!='')">
    <DIV>
    <xsl:if test="$location/city!=''">
      <xsl:value-of select="normalize-space($location/city)"/>
    </xsl:if>
    <xsl:if test="$location/state!=''">
      <xsl:text>, </xsl:text>
      <xsl:value-of select="normalize-space($location/state)"/>
    </xsl:if>
    <xsl:if test="$location/postalCode!=''">
      <xsl:text> </xsl:text>
      <xsl:value-of select="normalize-space($location/postalCode)"/>
    </xsl:if>
    <xsl:if test="$location/country!=''">
      <xsl:text> </xsl:text>
      <xsl:value-of select="normalize-space($location/country)"/>
    </xsl:if>
    </DIV>
  </xsl:if>
  <xsl:if test="($location/latitude!='') or ($location/longitude!='')">
    <DIV>
    <xsl:value-of select="normalize-space($location/latitude)"/>
    <xsl:text>, </xsl:text>
    <xsl:value-of select="normalize-space($location/longitude)"/>
    </DIV>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                      format-postalAddress                         -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Standard formatting for postalAddress within physicalLocation  -->

<xsl:template name="format-postalAddress">
  <xsl:param name="location" select="./postalAddress"/>
  <xsl:if test="$location/fullAddress!=''">
    <DIV>
    <xsl:value-of select="normalize-space($location/fullAddress)"/>
    </DIV>
  </xsl:if>
  <xsl:for-each select="$location/addressLine">
    <DIV>
    <xsl:value-of select="normalize-space(.)"/>
    </DIV>
  </xsl:for-each>
  <xsl:if test="$location/apartmentNumber!=''">
    <DIV>
    <xsl:text>Apartment </xsl:text>
    <xsl:value-of select="normalize-space($location/apartmentNumber)"/>
    </DIV>
  </xsl:if>
  <xsl:if test="$location/suite!=''">
    <DIV>
    <xsl:text>Suite </xsl:text>
    <xsl:value-of select="normalize-space($location/suite)"/>
    </DIV>
  </xsl:if>
  <xsl:if test="$location/privateMailBox!=''">
    <DIV>
    <xsl:text>MSC </xsl:text>
    <xsl:value-of select="normalize-space($location/privateMailBox)"/>
    </DIV>
  </xsl:if>
  <xsl:if test="$location/county!=''">
    <DIV>
    <xsl:value-of select="normalize-space($location/county)"/>
    <xsl:text> County</xsl:text>
    </DIV>
  </xsl:if>
  <xsl:if test="($location/city!='') or ($location/state!='') or ($location/postalCode!='') or ($location/country!='')">
    <DIV>
    <xsl:if test="$location/city!=''">
      <xsl:value-of select="normalize-space($location/city)"/>
    </xsl:if>
    <xsl:if test="$location/state!=''">
      <xsl:text>, </xsl:text>
      <xsl:value-of select="normalize-space($location/state)"/>
    </xsl:if>
    <xsl:if test="$location/postalCode!=''">
      <xsl:text> </xsl:text>
      <xsl:value-of select="normalize-space($location/postalCode)"/>
    </xsl:if>
    <xsl:if test="$location/country!=''">
      <xsl:text> </xsl:text>
      <xsl:value-of select="normalize-space($location/country)"/>
    </xsl:if>
    </DIV>
  </xsl:if>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                          append-number                            -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Append a number to a telephone number sequence   -->

<!--   This is a variation of prepent-attribute but it works in the
       opposite direction and uses hyphens instead of semicolons 
       and spaces
-->

<xsl:template name="append-number">
  <xsl:param name="segment"/>
  <xsl:param name="number"/>
  <xsl:param name="separator">
    <xsl:text>-</xsl:text>
  </xsl:param>
  <xsl:variable name="result">
    <xsl:choose>
    <xsl:when test="$number!=''">
      <xsl:choose>
        <xsl:when test="$segment!=''">
          <xsl:value-of select="$number"/>
          <xsl:value-of select="$separator"/>
          <xsl:value-of select="$segment"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$number"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$segment"/>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:value-of select="$result"/>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                        format-telephone                           -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formatting of a telephone number   -->

<xsl:template name="format-telephone">
  <xsl:param name="node" select="."/>
  <xsl:variable name="r45">
    <xsl:call-template name="append-number">
      <xsl:with-param name="segment" select="$node/telephonePrefix/telephoneCityCode"/>
      <xsl:with-param name="number"  select="$node/telephonePrefix/telephoneCountryCode"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r345">
    <xsl:call-template name="append-number">
      <xsl:with-param name="segment" select="$node/telephonePrefix/areaCode"/>
      <xsl:with-param name="number"  select="$r45"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r2345">
    <xsl:call-template name="append-number">
      <xsl:with-param name="segment" select="$node/telephoneNumber"/>
      <xsl:with-param name="number"  select="$r345"/>
    </xsl:call-template>
  </xsl:variable>
  <xsl:variable name="r12345">
    <xsl:call-template name="append-number">
      <xsl:with-param name="segment" select="$node/telephoneSuffix"/>
      <xsl:with-param name="number"  select="$r2345"/>
      <xsl:with-param name="separator">
        <xsl:text> </xsl:text>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:variable>
  <xsl:value-of select="$r12345"/>
</xsl:template>


<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->
<!--                          format-charge                            -->
<!-- - - - - - - - - - - - - - - - -+- - - - - - - - - - - - - - - - - -->

<!--   Formatting of a charge   -->

<xsl:template name="format-charge">
  <xsl:param name="node" select="."/>

  <TR>
    <TD COLSPAN="2">
      <B>
        <xsl:text>Charge</xsl:text>
        <xsl:if test="chargeSequenceNumber!=''">
          <xsl:text> </xsl:text>
          <xsl:value-of select="normalize-space(chargeSequenceNumber)"/>
        </xsl:if>
      </B>
    </TD>
  </TR>

  <xsl:if test="chargeNumber!=''">
    <TR>
      <TD ALIGN="RIGHT">Charge Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(chargeNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="chargeTrackingNumber!=''">
    <TR>
      <TD ALIGN="RIGHT">Charge Tracking Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(chargeTrackingNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(chargeCaseNumber)>0">
    <TR>
      <TD ALIGN="RIGHT">Charge Case Number</TD>
      <TD>
        <xsl:value-of select="normalize-space(chargeCaseNumber)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(agency)>0">
    <TR>
      <TD ALIGN="RIGHT" WIDTH="34%">Agency</TD>
      <TD WIDTH="66%">
        <xsl:call-template name="format-agency-list-no-parens"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(offenseDate)>0">
    <TR>
      <TD ALIGN="RIGHT">Offense Date</TD>
      <TD>
        <xsl:value-of select="normalize-space(offenseDate)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(chargeName)>0">
    <TR>
      <TD ALIGN="RIGHT">Charge Description</TD>
      <TD>
        <xsl:value-of select="normalize-space(chargeName)"/>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(chargeStatute)>0">
    <TR>
      <TD ALIGN="RIGHT">Statute</TD>
      <TD>
        <xsl:for-each select="chargeStatute">
          <DIV>
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:call-template name="format-attributes"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(offenseCode[@codeSource='NCIC'])>0">
    <TR>
      <TD ALIGN="RIGHT">NCIC Offense Code</TD>
      <TD>
        <xsl:for-each select="offenseCode[@codeSource='NCIC']">
          <xsl:if test="position()>1">
            <xsl:text>, </xsl:text>
          </xsl:if>
          <xsl:value-of select="normalize-space(.)"/>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>  

  <xsl:if test="count(offenseCode[@codeSource!='NCIC'])>0">
    <TR>
      <TD ALIGN="RIGHT">State Offense Code</TD>
      <TD>
        <xsl:for-each select="offenseCode[@codeSource!='NCIC']">
          <xsl:if test="position()>1">
            <xsl:text>, </xsl:text>
          </xsl:if>
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:call-template name="format-attributes"/>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>  

  <xsl:if test="count(numberOfIdenticalCharges)>0">
    <TR>
      <TD ALIGN="RIGHT">Counts</TD>
      <TD>
        <DIV>
          <xsl:value-of select="normalize-space(numberOfIdenticalCharges)"/>
        </DIV>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(chargeSeverity)>0">
    <TR>
      <TD ALIGN="RIGHT">Severity</TD>
      <TD>
        <DIV>
          <xsl:value-of select="normalize-space(chargeSeverity)"/>
        </DIV>
      </TD>
    </TR>
  </xsl:if>

  <xsl:if test="count(inchoateCharge)>0">
    <TR>
      <TD ALIGN="RIGHT">Inchoate Charge</TD>
      <TD>
        <xsl:for-each select="inchoateCharge">
          <xsl:if test="position()>1">
            <xsl:text>, </xsl:text>
          </xsl:if>
          <xsl:value-of select="normalize-space(.)"/>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>  

  <xsl:if test="count(chargeEnhancingFactor)>0">
    <TR>
      <TD ALIGN="RIGHT">Enhancing Factor</TD>
      <TD>
        <xsl:for-each select="chargeEnhancingFactor">
          <DIV>
          <xsl:value-of select="normalize-space(.)"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>  

  <xsl:if test="count(chargeReducingFactor)>0">
    <TR>
      <TD ALIGN="RIGHT">Reducing Factor</TD>
      <TD>
        <xsl:for-each select="chargeReducingFactor">
          <DIV>
          <xsl:value-of select="normalize-space(.)"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>  

  <xsl:if test="count(chargeDisposition)>0">
    <TR>
      <TD ALIGN="RIGHT">Disposition</TD>
      <TD>
        <xsl:for-each select="chargeDisposition">
          <DIV>
          <xsl:value-of select="normalize-space(.)"/>
          <xsl:call-template name="format-attributes"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>  

  <xsl:if test="count(comment)>0">
    <TR>
      <TD ALIGN="RIGHT">
        <xsl:text>Comment(s)</xsl:text>
      </TD>
      <TD>
        <xsl:for-each select="comment">
          <DIV>
            <xsl:value-of select="normalize-space(.)"/>
          </DIV>
        </xsl:for-each>
      </TD>
    </TR>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

