<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:incident-doc="http://www.it.ojp.gov/jxdm/doc/incident/1.1/document"
	xmlns:rec="http://wijis.wisconsin.gov/specs/schemas/record/v1.1/2007-01-12/"
	xmlns:incident="http://www.it.ojp.gov/jxdm/doc/incident/1.1/extension"
	xmlns:jxdm="http://www.it.ojp.gov/jxdm/3.0.2"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

	<xsl:output method="html" indent="yes"/>

	<!-- 
	This stylesheet-level parameter must be supplied by the system, because 
	the IEPD does not have a place for this information.
	
	The design intent here is that the Gateway *does* know the Submitter at
	runtime, and can supply the Submitter's display name as a parameter to the
	XSLT processor.
	
	The default value signals that the parameter has not been successfully passed.
-->
	<xsl:param name="recordAgencyName">(Record owning agency name not supplied by system)</xsl:param>

	<!--======================== ROOT TEMPLATE  ========================-->

	<xsl:template match="rec:retrievedRecord">
		<xsl:element name="html">
			<xsl:element name="head">
				<xsl:element name="link">
					<xsl:attribute name="rel">stylesheet</xsl:attribute>
					<xsl:attribute name="type">text/css</xsl:attribute>
					<xsl:attribute name="href">/gateway/css/incident_iepd_display.css</xsl:attribute>
				</xsl:element>
				<xsl:element name="script">
					<xsl:attribute name="type">text/javascript</xsl:attribute>
					<xsl:attribute name="src">js/incident_report.js</xsl:attribute>
				</xsl:element>
				<xsl:element name="meta">
					<xsl:attribute name="http-equiv">Refresh</xsl:attribute>
					<xsl:attribute name="content">1800;url=/gateway/logout.htm</xsl:attribute>
				</xsl:element>
				<xsl:element name="meta">
					<xsl:attribute name="http-equiv">CACHE-CONTROL</xsl:attribute>
					<xsl:attribute name="content">NO-CACHE</xsl:attribute>
				</xsl:element>
				<xsl:element name="meta">
					<xsl:attribute name="http-equiv">PRAGMA</xsl:attribute>
					<xsl:attribute name="content">NO-CACHE</xsl:attribute>
				</xsl:element>
			</xsl:element>

			<xsl:element name="body">
				<xsl:attribute name="onLoad">setTimeout(window.close,1800000)</xsl:attribute>

				<xsl:element name="p">
					<xsl:attribute name="class">textAlignCenter</xsl:attribute>
					<xsl:element name="span">
						<xsl:attribute name="class">imageContainerHeader</xsl:attribute>
						<xsl:element name="img">
							<xsl:attribute name="src"
							>/gateway/images/wijis_banner.jpg</xsl:attribute>
						</xsl:element>
					</xsl:element>
				</xsl:element>

				<xsl:element name="p">
					<xsl:attribute name="class">wijis_top_text</xsl:attribute>
					<xsl:text>For official criminal justice use only</xsl:text>
				</xsl:element>
				<xsl:element name="div">
					<xsl:attribute name="class">pageheader</xsl:attribute>

					<font color="red">
						<xsl:value-of select="$recordAgencyName"/>
					</font>
				</xsl:element>
				<xsl:element name="div">
					<xsl:attribute name="class">title</xsl:attribute> Incident Report </xsl:element>

				<!--( Code below will display activity ID as case number if it present,
                       it can be found in the path  mentioned "incident:IncidentReportIncident/jxdm:ActivityID/jxdm:ID".
                       And if above element is empty, it will pull out value from
                       "incident:IncidentReportIncident/jxdm:ActivityCrimeCase/jxdm:CaseTrackingID/jxdm:ID")-->

				<xsl:variable name="uniqeActivityID"
					select="//incident:IncidentReportIncident/jxdm:ActivityID/jxdm:ID "/>
				<xsl:choose>
					<xsl:when test="$uniqeActivityID != ' ' ">
						<xsl:call-template name="activityID">
							<xsl:with-param name="activityIDNode"
								select="//incident:IncidentReportIncident/jxdm:ActivityID/jxdm:ID"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:if test="//incident:IncidentReportIncident/jxdm:ActivityCrimeCase">
							<xsl:call-template name="activityID">
								<xsl:with-param name="activityIDNode"
									select="//incident:IncidentReportIncident/jxdm:ActivityCrimeCase/jxdm:CaseTrackingID/jxdm:ID"
								/>
							</xsl:call-template>
						</xsl:if>
					</xsl:otherwise>
				</xsl:choose>

				<xsl:apply-templates select="//incident:IncidentReportIncident"/>
				<!-- (note that above template calls the partiesInvolvedTemplate by
				name, delegating that part of its work; "parties involved" is
				not a logical component of the IEPD, so it's assembled at
				the IncidentReportIncident level.) -->
				<xsl:apply-templates
					select="//incident:IncidentReportIncident/incident:IncidentResponse"/>

				<xsl:apply-templates select="//incident:ServiceCall"/>

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

				<xsl:element name="p">
					<xsl:attribute name="class">wijis_top_text</xsl:attribute>
					<xsl:text>For official criminal justice use only</xsl:text>
				</xsl:element>

			</xsl:element>
		</xsl:element>
	</xsl:template>

	<!--======================== INCIDENT REPORT TEMPLATE =========================-->

	<xsl:template match="incident-doc:IncidentReport">
		<xsl:if test="@*[normalize-space()]">
			<xsl:element name="table">
				<xsl:attribute name="class">relative</xsl:attribute>
				<xsl:element name="tr">
					<xsl:if test="@jxdm:reportingOrganizationText[normalize-space()]">
						<xsl:element name="th">
							<xsl:attribute name="class">group</xsl:attribute>
							<xsl:text>Reporting Organization</xsl:text>
						</xsl:element>
					</xsl:if>
					<!--  <xsl:if test="@jxdm:sourceIDText[normalize-space()]">
					<xsl:element name='th'>
						<xsl:attribute name='class'>group</xsl:attribute>
						<xsl:text>Source ID</xsl:text>
					</xsl:element>
					</xsl:if>-->
				</xsl:element>
				<xsl:element name="tr">
					<xsl:if test="@jxdm:reportingOrganizationText[normalize-space()]">
						<xsl:element name="td">
							<xsl:value-of select="@jxdm:reportingOrganizationText"/>
						</xsl:element>
					</xsl:if>
					<!-- <xsl:if test="@jxdm:sourceIDText[normalize-space()]">
					<xsl:element name='td'>
						<xsl:value-of select='@jxdm:sourceIDText'/>
						</xsl:element>
						</xsl:if>-->
				</xsl:element>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<!--======================== SERVICE CALL TEMPLATE =======================-->

	<xsl:template match="incident:ServiceCall">
		<xsl:element name="div">
			<xsl:attribute name="class">block</xsl:attribute>

			<xsl:element name="span">
				<xsl:attribute name="class">blockcaption</xsl:attribute>
				<xsl:text>Service Call Information</xsl:text>
			</xsl:element>

			<xsl:element name="table">
				<xsl:attribute name="class">normal</xsl:attribute>

				<xsl:element name="div">
					<xsl:variable name="statusDate" select="//jxdm:ActivityStatus/jxdm:StatusDate"/>
					<xsl:if test=" $statusDate != '' ">
						<xsl:attribute name="class">metadata</xsl:attribute>
						<xsl:text>Status Date : </xsl:text>
						<xsl:value-of select="$statusDate"/>
					</xsl:if>
				</xsl:element>
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Activity</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>End</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:attribute name="rowspan">2</xsl:attribute>
						<xsl:text>Completed</xsl:text>
					</xsl:element>
				</xsl:element>

				<!-- 
			<tr>
				<th>Date</th>
				<th>Time</th>
				<th>Date</th>
				<th>Time</th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Date</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Time</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Date</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Time</xsl:text>
					</xsl:element>
				</xsl:element>

				<xsl:element name="tr">
					<xsl:element name="td">
						<xsl:value-of select="jxdm:ActivityDate"/>
					</xsl:element>
					<xsl:element name="td">
						<!-- <xsl:value-of select='jxdm:ActivityTime'/>-->
						<xsl:call-template name="formatTime">
							<xsl:with-param name="time" select="jxdm:ActivityTime"/>
						</xsl:call-template>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="jxdm:ActivityEndDate"/>
					</xsl:element>
					<xsl:element name="td">
						<!--<xsl:value-of select='jxdm:ActivityEndTime'/>-->
						<xsl:call-template name="formatTime">
							<xsl:with-param name="time" select="jxdm:ActivityEndTime"/>
						</xsl:call-template>
					</xsl:element>
					<xsl:element name="td">
						<xsl:apply-templates select="jxdm:ActivityCompletedIndicator"/>
					</xsl:element>
				</xsl:element>

				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">5</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Call Arrived</xsl:text>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<th>Date</th>
				<th>Time</th>
				<th>Via</th>
				<th>Operator</th>
				<th>Dispatcher</th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Date</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Time</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Via</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Operator</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Dispatcher</xsl:text>
					</xsl:element>
				</xsl:element>

				<xsl:element name="tr">
					<xsl:element name="td">
						<xsl:value-of select="jxdm:ServiceCallArrivedDate"/>
					</xsl:element>
					<xsl:element name="td">
						<!--<xsl:value-of select='jxdm:ServiceCallArrivedTime'/>-->
						<xsl:call-template name="formatTime">
							<xsl:with-param name="time" select="jxdm:ServiceCallArrivedTime"/>
						</xsl:call-template>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="jxdm:ServiceCallMechanismText"/>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="incident:ServiceCallDispatcher"/>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="incident:ServiceCallOperator"/>
					</xsl:element>
				</xsl:element>
			</xsl:element>

			<!-- ==================== Table for Service Call Response========================-->

			<xsl:element name="table">
				<xsl:attribute name="class">normal</xsl:attribute>

				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">5</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Service Call Response</xsl:text>
					</xsl:element>
				</xsl:element>

				<xsl:variable name="formattedServiceCallAddress">
					<xsl:call-template name="streetAddressFormatter">
						<xsl:with-param name="locationAddressNode"
							select="incident:ServiceCallResponseLocation/jxdm:LocationAddress"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:if test="string-length(normalize-space($formattedServiceCallAddress) )">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:attribute name="colspan">5</xsl:attribute>
							<xsl:text>Location</xsl:text>
						</xsl:element>
					</xsl:element>

					<xsl:element name="tr">
						<xsl:element name="td">
							<xsl:attribute name="colspan">5</xsl:attribute>
							<xsl:value-of select="$formattedServiceCallAddress"/>
							<xsl:call-template name="displayMap">
								<xsl:with-param name="address" select="$formattedServiceCallAddress"/>
								<xsl:with-param name="mapID" select="generate-id()"/>
							</xsl:call-template>
						</xsl:element>
					</xsl:element>
				</xsl:if>


				<xsl:if
					test="boolean(string-length(normalize-space(incident:ServiceCallResponseLocation/jxdm:LocationLandmarkText)) &gt; 0)">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:attribute name="colspan">5</xsl:attribute>
							<xsl:text>Location Land Mark</xsl:text>
						</xsl:element>
					</xsl:element>
					<xsl:element name="tr">
						<xsl:element name="td">
							<xsl:attribute name="colspan">5</xsl:attribute>
							<xsl:value-of
								select="incident:ServiceCallResponseLocation/jxdm:LocationLandmarkText"
							/>
						</xsl:element>
					</xsl:element>
				</xsl:if>


				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">5</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Contact Person</xsl:text>
					</xsl:element>
				</xsl:element>

				<xsl:element name="tr">
					<xsl:element name="td">
						<xsl:attribute name="colspan">5</xsl:attribute>
						<xsl:if
							test="incident:ServiceCallResponseLocation//jxdm:ContactInformationDescriptionText">
							<xsl:value-of
								select="incident:ServiceCallResponseLocation//jxdm:ContactInformationDescriptionText"
							/>
						</xsl:if>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<th>Name</th>
				<th>Employment Position</th>
				<th>Employed By</th>
				<th class='empty'> </th>
				<th class='empty'> </th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Name</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Employment Position</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Employed By</xsl:text>
					</xsl:element>
				</xsl:element>

				<xsl:element name="tr">
					<xsl:element name="td">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:if test=".//incident:ContactPerson/jxdm:PersonName">
							<xsl:value-of select=".//incident:ContactPerson/jxdm:PersonName"/>
						</xsl:if>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of
							select=".//incident:ContactPerson//incident:Employment//jxdm:EmploymentPositionName"
						/>
					</xsl:element>
					<xsl:element name="td">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:value-of
							select=".//incident:ContactPerson//incident:Employment//jxdm:OrganizationName"
						/>
					</xsl:element>
				</xsl:element>
			</xsl:element>
		</xsl:element>
	</xsl:template>

	<!--====================CASE NUMBER TEMPLATE=======================-->

	<xsl:template name="activityID">
		<xsl:param name="activityIDNode"/>
		<xsl:element name="div">
			<!--<xsl:if test="$activityID != '' ">-->
			<xsl:attribute name="class">metadata</xsl:attribute>
			<xsl:text>Case No. (or alternate form of associated record identifier): </xsl:text>
			<xsl:value-of select="$activityIDNode"/>
			<!--</xsl:if>-->
		</xsl:element>
	</xsl:template>

	<!--=========================INCIDENT RESPONSE TEMPLATE=================-->

	<xsl:template match="incident:IncidentReportIncident/incident:IncidentResponse">

		<xsl:element name="div">
			<xsl:attribute name="class">block</xsl:attribute>
			<!-- 
		<span class='blockcaption'>Incident Response</span>
-->
			<xsl:element name="span">
				<xsl:attribute name="class">blockcaption</xsl:attribute>
				<xsl:text>Incident Response</xsl:text>
			</xsl:element>

			<!--
		<table class='normal'>
-->
			<xsl:element name="table">
				<xsl:attribute name="class">normal</xsl:attribute>
				<xsl:if test="incident:IncidentResponsePersonRole">

					<!-- 
			<tr>
				<th colspan='3' class='group'>Response Person</th>
			</tr>
-->
					<xsl:apply-templates select="//incident:IncidentResponsePersonRole"/>

					<xsl:call-template name="IncidentResponseOrganization">
						<xsl:with-param name="responseOrganization"
							select="incident:IncidentResponseOrganization"/>
					</xsl:call-template>

				</xsl:if>
			</xsl:element>
		</xsl:element>


		<!--
		<table class='normal narrow'>
-->
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>

			<!--
			<tr>
				<th colspan='2' class='group'>Incident Observation</th>
			</tr>
-->
			<xsl:if test="jxdm:IncidentObservationText[normalize-space()]">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Incident Observation</xsl:text>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<td colspan='2' >Arrived on the scene and observed subject and victim Bart shouting at one another...</td>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:variable name="observation" select="jxdm:IncidentObservationText"/>
					<xsl:element name="td">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:if test="$observation">
							<xsl:value-of select="$observation"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!-- Moved Incident Arrest inforamtion to separate template called IncidentArrest-->

			<xsl:apply-templates select="incident:IncidentArrest"/>

		</xsl:element>
	</xsl:template>

	<!--===================== INCIDENT INFORMATION TEMPLATE ===============-->

	<xsl:template match="incident:IncidentReportIncident">

		<!-- 
	<div class='block'>
-->
		<xsl:element name="div">
			<xsl:attribute name="class">block</xsl:attribute>

			<!--
		<span class='blockcaption'>Incident Information</span>
-->
			<xsl:element name="span">
				<xsl:attribute name="class">blockcaption</xsl:attribute>
				<xsl:text>Incident Information</xsl:text>
			</xsl:element>

			<xsl:if test="@*[normalize-space()]">
				<xsl:element name="table">
					<xsl:attribute name="class">relative</xsl:attribute>
					<xsl:element name="tr">
						<xsl:if test="@jxdm:commentText[normalize-space()]">
							<xsl:element name="th">
								<xsl:attribute name="class">group</xsl:attribute>
								<xsl:text>Comment</xsl:text>
							</xsl:element>
						</xsl:if>
						<xsl:if test="@jxdm:id[normalize-space()]">
							<xsl:element name="th">
								<xsl:attribute name="class">group</xsl:attribute>
								<xsl:text>ID</xsl:text>
							</xsl:element>
						</xsl:if>
						<xsl:if test="@jxdm:reportedDate[normalize-space()]">
							<xsl:element name="th">
								<xsl:attribute name="class">group</xsl:attribute>
								<xsl:text>Reported Date</xsl:text>
							</xsl:element>
						</xsl:if>
					</xsl:element>
					<xsl:element name="tr">
						<xsl:if test="@jxdm:commentText[normalize-space()]">
							<xsl:element name="td">
								<xsl:attribute name="align">center</xsl:attribute>
								<xsl:value-of select="@jxdm:commentText"/>
							</xsl:element>
						</xsl:if>
						<xsl:if test="@jxdm:id[normalize-space()]">
							<xsl:element name="td">
								<xsl:attribute name="align">center</xsl:attribute>
								<xsl:value-of select="@jxdm:id"/>
							</xsl:element>
						</xsl:if>
						<xsl:if test="@jxdm:reportedDate[normalize-space()]">
							<xsl:element name="td">
								<xsl:attribute name="align">center</xsl:attribute>
								<xsl:value-of select="@jxdm:reportedDate"/>
							</xsl:element>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="statusText" select="//jxdm:ActivityStatus/jxdm:StatusText"/>
			<xsl:element name="table">
				<xsl:attribute name="class">normal</xsl:attribute>

				<!--
			<tr>
				<th colspan='2' class='group'>Activity</th>
				<th colspan='2' class='group'>End</th>
				<th rowspan='2'>Completed</th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Activity</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>End</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:attribute name="rowspan">2</xsl:attribute>
						<xsl:text>Completed</xsl:text>
					</xsl:element>
					<!--<xsl:if test="$statusText != '' ">-->
					<xsl:element name="th">
						<xsl:attribute name="rowspan">2</xsl:attribute>
						<xsl:text>Status Text</xsl:text>
					</xsl:element>

				</xsl:element>

				<!--
			<tr>
				<th>Date</th>
				<th>Time</th>
				<th>Date</th>
				<th>Time</th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Date</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Time</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Date</xsl:text>
					</xsl:element>
					<xsl:element name="th">
						<xsl:text>Time</xsl:text>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<td>2005-03-01</td>
				<td>22:03:00</td>
				<td>2005-03-01</td>
				<td>22:04:00</td>
				<td>true</td>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="td">
						<xsl:value-of select="jxdm:ActivityDate"/>
					</xsl:element>
					<xsl:element name="td">
						<!--<xsl:value-of select='jxdm:ActivityTime'/>-->
						<xsl:call-template name="formatTime">
							<xsl:with-param name="time" select="jxdm:ActivityTime"/>
						</xsl:call-template>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="jxdm:ActivityEndDate"/>
					</xsl:element>
					<xsl:element name="td">
						<!--<xsl:value-of select='jxdm:ActivityEndTime'/>-->
						<xsl:call-template name="formatTime">
							<xsl:with-param name="time" select="jxdm:ActivityEndTime"/>
						</xsl:call-template>
					</xsl:element>
					<xsl:element name="td">
						<xsl:apply-templates select="jxdm:ActivityCompletedIndicator"/>
					</xsl:element>
					<!--<xsl:if test="$statusText != '' ">-->
					<xsl:element name="td">
						<xsl:value-of select="$statusText"/>
					</xsl:element>
				</xsl:element>

		<!--=================== Activity Description Text =================== -->

				<xsl:variable name="activityDescriptionText"
					select="//jxdm:ActivityDescriptionText[normalize-space()]"/>

				<xsl:if test="$activityDescriptionText">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:attribute name="colspan">6</xsl:attribute>
							<xsl:attribute name="class">group</xsl:attribute>
							<xsl:text>Description Text</xsl:text>
						</xsl:element>
					</xsl:element>
					<xsl:element name="tr">
						<xsl:element name="td">
							<xsl:attribute name="colspan">6</xsl:attribute>
							<xsl:value-of disable-output-escaping="yes"
								select="$activityDescriptionText"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<xsl:if test="$activityDescriptionText/@jxdm:commentText != ''">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:attribute name="colspan">6</xsl:attribute>
							<xsl:attribute name="class">group</xsl:attribute>
							<xsl:text>Comment</xsl:text>
						</xsl:element>
					</xsl:element>
					<xsl:element name="tr">
						<xsl:element name="td">
							<xsl:attribute name="colspan">6</xsl:attribute>
							<xsl:value-of disable-output-escaping="yes"
								select="$activityDescriptionText/@jxdm:commentText"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">6</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Incident Narrative</xsl:text>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<td colspan='5'>
					Mr. Gumble was getting a six-pack out of the refrigerator case when he saw Bart Simpson put the box
					of twinkies under his coat. Meanwhile, he saw Homer Simpson watching the door.  When shouting began,
					Homer ran out the door and sped off in the Simpson family car.
				</td>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="td">
						<xsl:attribute name="colspan">6</xsl:attribute>
						<xsl:value-of disable-output-escaping="yes"
							select="../incident:IncidentReportNarrative"/>
					</xsl:element>
				</xsl:element>

				<!--
		</table>
-->
			</xsl:element>
			<!--==========	Code below will execute if ActivityCrimeCase element is present  ==========-->

			<xsl:if test="//jxdm:ActivityCrimeCase">
				<xsl:element name="table">
					<xsl:attribute name="class">normal narrow</xsl:attribute>

					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:attribute name="colspan">2</xsl:attribute>
							<xsl:attribute name="class">group</xsl:attribute>
							<xsl:text>Activity Crime Case</xsl:text>
						</xsl:element>
					</xsl:element>

					<!-- Id's to bottom 
                                               <xsl:element name='tr'>
					<xsl:element name='th'>
						<xsl:text>Source ID Text</xsl:text>
					</xsl:element>
					<xsl:element name='td'>
						<xsl:value-of select='//jxdm:ActivityCrimeCase/@jxdm:sourceIDText'/>
					</xsl:element>
				</xsl:element>-->

					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Case Domestic Violence Indicator</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of
								select="//jxdm:ActivityCrimeCase/jxdm:CaseDetails/jxdm:CaseDomesticViolenceIndicator"
							/>
						</xsl:element>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--=============== End Of Activity Crime Case  table =======================-->

			<xsl:element name="table">
				<xsl:attribute name="class">normal narrow</xsl:attribute>

				<!--
			<tr>
				<th colspan='2' class='group'>Location</th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:text>Location</xsl:text>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<th>Address</th>
				<td>111 Fifth Avenue<br/>Olympia, WA</td>
			</tr>
-->
				<!--=====================  Incident Location  ===========================-->

				<!-- Id's to Bottom
			    <xsl:if test="incident:IncidentLocation/@jxdm:id[normalize-space()]">
				<xsl:call-template name="showElement">
					<xsl:with-param name="header">ID</xsl:with-param>
					<xsl:with-param name="value" select='incident:IncidentLocation/@jxdm:id' />
				</xsl:call-template>
			</xsl:if>-->
				<xsl:if
					test="incident:IncidentLocation/@jxdm:reportingOrganizationText[normalize-space()]">
					<xsl:call-template name="showElement">
						<xsl:with-param name="header">Reporting Organization</xsl:with-param>
						<xsl:with-param name="value"
							select="incident:IncidentLocation/@jxdm:reportingOrganizationText"/>
					</xsl:call-template>
				</xsl:if>

				<!--  Id's to Bottom
		        <xsl:if test="incident:IncidentLocation/@jxdm:sourceIDText[normalize-space()]">
				<xsl:call-template name="showElement">
					<xsl:with-param name="header">Source ID</xsl:with-param>
					<xsl:with-param name="value" select='incident:IncidentLocation/@jxdm:sourceIDText' />
				</xsl:call-template>
				</xsl:if>-->

				<!--========= Location code for incident=========== -->
				<xsl:variable name="locationTypeCode"
					select="incident:IncidentLocation/jxdm:LocationTypeCode"/>
				<xsl:if test="$locationTypeCode != ''">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Location Type Code</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$locationTypeCode"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<xsl:variable name="locationSecondaryUnit"
					select="incident:IncidentLocation/jxdm:LocationAddress/jxdm:LocationSecondaryUnitText[normalize-space()]"/>
				<xsl:if test="$locationSecondaryUnit">
					<xsl:call-template name="showElement">
						<xsl:with-param name="header">Location Secondary Unit</xsl:with-param>
						<xsl:with-param name="value" select="$locationSecondaryUnit"/>
					</xsl:call-template>
				</xsl:if>

				<xsl:variable name="formattedIncidentAddress">
					<xsl:call-template name="streetAddressFormatter">
						<xsl:with-param name="locationAddressNode"
							select="incident:IncidentLocation/jxdm:LocationAddress"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:if test="$formattedIncidentAddress">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Address</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$formattedIncidentAddress"/>
							<xsl:call-template name="displayMap">
								<xsl:with-param name="address" select="$formattedIncidentAddress"/>
								<xsl:with-param name="mapID" select="generate-id()"/>
							</xsl:call-template>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
		</table>
-->
			</xsl:element>

			<!--
		<table class='normal narrow'>
-->
			<xsl:element name="table">
				<xsl:attribute name="class">normal narrow</xsl:attribute>

				<!--
			<tr>
				<th>Number of Structures Entered</th>
				<td>1</td>
			</tr>
-->
				<xsl:variable name="numberStructuresEntered"
					select="jxdm:IncidentStructuresEnteredQuantity"/>
				<xsl:if test="$numberStructuresEntered">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Number of Structures Entered</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:if test="$numberStructuresEntered">
								<xsl:value-of select="$numberStructuresEntered"/>
							</xsl:if>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
			<tr>
				<th>Number of Vehicles Stolen</th>
				<td>0</td>
			</tr>
-->
				<xsl:variable name="numberVehiclesStolen"
					select="jxdm:IncidentStolenVehicleQuantity"/>
				<xsl:if test="$numberVehiclesStolen">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Number of Vehicles Stolen</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:if test="$numberVehiclesStolen">
								<xsl:value-of select="$numberVehiclesStolen"/>
							</xsl:if>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
			<tr>
				<th>Number of Vehicles Recovered</th>
				<td>0</td>
			</tr>
-->
				<xsl:variable name="numberVehiclesRecovered"
					select="jxdm:IncidentRecoveredVehicleQuantity"/>
				<xsl:if test="$numberVehiclesRecovered">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Number of Vehicles Recovered</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:if test="$numberVehiclesRecovered">
								<xsl:value-of select="$numberVehiclesRecovered"/>
							</xsl:if>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
		</table>
-->
			</xsl:element>

			<!-- create tables for Offense element(s) if any -->
			<xsl:apply-templates select="jxdm:Offense"/>

			<!--
	</div>
-->
		</xsl:element>


		<!-- call the "parties involved" template (which was pulled
		out of this template to make this smaller and more
		manageable.) -->
		<xsl:call-template name="partiesInvolvedTemplate"/>


		<!-- display Involved Property info -->
		<xsl:variable name="propertyInvolved" select="incident:IncidentInvolvedProperty"/>
		<xsl:if test="$propertyInvolved">
			<!-- 
		<div class='block'>
	-->
			<xsl:element name="div">
				<xsl:attribute name="class">block</xsl:attribute>

				<!--
			<span class='blockcaption'>Involved Property</span>
	-->
				<xsl:element name="span">
					<xsl:attribute name="class">blockcaption</xsl:attribute>
					<xsl:text>Involved Property</xsl:text>
				</xsl:element>

				<xsl:apply-templates select="$propertyInvolved"/>
			</xsl:element>
		</xsl:if>

		<!-- display Involved Structures info -->
		<xsl:variable name="structuresInvolved" select="incident:IncidentInvolvedStructure"/>
		<xsl:if test="$structuresInvolved">
			<!-- 
		<div class='block'>
	-->
			<xsl:element name="div">
				<xsl:attribute name="class">block</xsl:attribute>

				<!--
			<span class='blockcaption'>Involved Structures</span>
	-->
				<xsl:element name="span">
					<xsl:attribute name="class">blockcaption</xsl:attribute>
					<xsl:text>Involved Structures</xsl:text>
				</xsl:element>

				<xsl:apply-templates select="$structuresInvolved"/>
			</xsl:element>
		</xsl:if>

		<!-- display Involved Weapons info -->
		<xsl:variable name="weaponsInvolved" select="incident:IncidentInvolvedWeapon"/>
		<xsl:if test="$weaponsInvolved">
			<!-- 
		<div class='block'>
	-->
			<xsl:element name="div">
				<xsl:attribute name="class">block</xsl:attribute>

				<!--
			<span class='blockcaption'>Involved Weapons</span>
	-->
				<xsl:element name="span">
					<xsl:attribute name="class">blockcaption</xsl:attribute>
					<xsl:text>Involved Weapons</xsl:text>
				</xsl:element>

				<xsl:apply-templates select="$weaponsInvolved"/>
			</xsl:element>
		</xsl:if>

		<!-- display Involved Firearms info -->
		<xsl:variable name="firearmsInvolved" select="incident:IncidentInvolvedFirearm"/>
		<xsl:if test="$firearmsInvolved">
			<!-- 
		<div class='block'>
	-->
			<xsl:element name="div">
				<xsl:attribute name="class">block</xsl:attribute>

				<!--
			<span class='blockcaption'>Involved Firearms</span>
	-->
				<xsl:element name="span">
					<xsl:attribute name="class">blockcaption</xsl:attribute>
					<xsl:text>Involved Firearms</xsl:text>
				</xsl:element>

				<xsl:apply-templates select="$firearmsInvolved"/>
			</xsl:element>
		</xsl:if>

		<!-- display Involved Vehicles info -->
		<xsl:variable name="vehiclesInvolved" select="incident:IncidentInvolvedVehicle"/>
		<xsl:if test="$vehiclesInvolved">
			<!-- 
		<div class='block'>
	-->
			<xsl:element name="div">
				<xsl:attribute name="class">block</xsl:attribute>

				<!--
			<span class='blockcaption'>Involved Vehicles</span>
	-->
				<xsl:element name="span">
					<xsl:attribute name="class">blockcaption</xsl:attribute>
					<xsl:text>Involved Vehicles</xsl:text>
				</xsl:element>

				<xsl:apply-templates select="$vehiclesInvolved"/>
			</xsl:element>
		</xsl:if>

		<!-- display Involved drugs info -->
		<xsl:variable name="drugsInvolved" select="incident:IncidentInvolvedDrug"/>
		<xsl:if test="$drugsInvolved">
			<!-- 
		<div class='block'>
	-->
			<xsl:element name="div">
				<xsl:attribute name="class">block</xsl:attribute>

				<!--
			<span class='blockcaption'>Involved Drugs</span>
	-->
				<xsl:element name="span">
					<xsl:attribute name="class">blockcaption</xsl:attribute>
					<xsl:text>Involved Drug</xsl:text>
				</xsl:element>

				<xsl:apply-templates select="$drugsInvolved"/>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<!--==================INCIDENT REPORT NDEX METADATA TEMPLATE==================-->

	<xsl:template match="incident:IncidentReportNDExIncidentMetadata">

		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>

			<xsl:variable name="nDExIncidentRecordActionTypeCode"
				select="incident:NDExIncidentRecordActionTypeCode"/>
			<xsl:if test="$nDExIncidentRecordActionTypeCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>NDEx Incident Record Action TypeCode</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$nDExIncidentRecordActionTypeCode">
							<xsl:value-of select="$nDExIncidentRecordActionTypeCode"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="nDExIncidentAgencyNotificationIndicator"
				select="incident:NDExIncidentAgencyNotificationIndicator"/>
			<xsl:if test="$nDExIncidentAgencyNotificationIndicator">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>NDEx Incident Agency Notification Indicator</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$nDExIncidentAgencyNotificationIndicator">
							<xsl:value-of select="$nDExIncidentAgencyNotificationIndicator"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="nDExIncidentIncidentVisibleIndicator"
				select="incident:NDExIncidentIncidentVisibleIndicator"/>
			<xsl:if test="$nDExIncidentIncidentVisibleIndicator">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>NDEx Incident IncidentVisible Indicator</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$nDExIncidentIncidentVisibleIndicator">
							<xsl:value-of select="$nDExIncidentIncidentVisibleIndicator"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="nDExIncidentNIBRSSubmissionIndicator"
				select="incident:NDExIncidentNIBRSSubmissionIndicator"/>
			<xsl:if test="$nDExIncidentNIBRSSubmissionIndicator">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>NDEx Incident NIBRSSubmission Indicator</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$nDExIncidentNIBRSSubmissionIndicator">
							<xsl:value-of select="$nDExIncidentNIBRSSubmissionIndicator"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

		</xsl:element>
	</xsl:template>

	<!--====================== PARTIES INVOLVED TEMPLATE  ======================-->

	<xsl:template name="partiesInvolvedTemplate">
		<!-- 
	<div class='block'>
-->
		<xsl:element name="div">
			<xsl:attribute name="class">block</xsl:attribute>

			<!--
		<span class='blockcaption'>Parties Involved In Incident</span>
-->
			<xsl:element name="span">
				<xsl:attribute name="class">blockcaption</xsl:attribute>
				<xsl:text>Parties Involved In Incident</xsl:text>
			</xsl:element>

			<!-- each involved party is displayed in a separate table; this
			table creation is delegated to these templates. In general,
			they create captions, add specific content, and call things like
			the personInfo template. -->

			<!-- display Subject info -->
			<xsl:apply-templates select="incident:IncidentSubject"/>

			<!-- display Victim info -->
			<xsl:apply-templates select="incident:IncidentVictim"/>

			<!-- display Witness info -->
			<xsl:apply-templates select="incident:IncidentWitness"/>

			<!-- display Involved Person info -->
			<xsl:apply-templates select="incident:IncidentPersonInvolvement"/>

		</xsl:element>
	</xsl:template>

	<!--======================= OFFENSE TEMPLATE   =======================-->

	<!-- This template creates a table, with header, for an Offense element. -->
	<xsl:template match="jxdm:Offense">


		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>

			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Offense Description and Codes</xsl:text>
				</xsl:element>
			</xsl:element>

			<xsl:variable name="statuteCodeID"
				select="jxdm:IncidentViolatedStatute/jxdm:StatuteCodeID/jxdm:ID[normalize-space()]"/>
			<xsl:if test="$statuteCodeID">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Statute Code ID</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$statuteCodeID">
							<xsl:value-of select="$statuteCodeID"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="statuteCode"
				select="jxdm:IncidentViolatedStatute/jxdm:StatuteOffenseCode[normalize-space()]"/>
			<xsl:if test="$statuteCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Statute Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$statuteCode">
							<xsl:value-of select="$statuteCode"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="statuteText"
				select="jxdm:IncidentViolatedStatute/jxdm:StatuteText[normalize-space()]"/>
			<!-- display row only if element is  found and it's not empty  -->
			<xsl:if test="$statuteText">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Statute Text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$statuteText">
							<xsl:value-of select="$statuteText"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="statuteTypeText"
				select="jxdm:IncidentViolatedStatute/jxdm:StatuteTypeText[normalize-space()]"/>
			<!-- display row only if element is  found and it's not empty  -->
			<xsl:if test="$statuteTypeText">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Statute Type Text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$statuteTypeText">
							<xsl:value-of select="$statuteTypeText"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="categoryTypeCode" select=".//jxdm:IncidentCategoryTypeCode"/>
			<xsl:if test="$categoryTypeCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Incident Category Type</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$categoryTypeCode">
							<xsl:value-of select="$categoryTypeCode"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="incidentFactorCode" select=".//jxdm:IncidentFactorCode"/>
			<xsl:if test="$incidentFactorCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Incident Factor Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$incidentFactorCode">
							<xsl:value-of select="$incidentFactorCode"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="nibrsBiasMotivation"
				select=".//jxdm:IncidentFactorCode.nibrsBiasMotivation"/>
			<xsl:if test="$nibrsBiasMotivation">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>NIBRS Bias Motivation</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$nibrsBiasMotivation">
							<xsl:value-of select="$nibrsBiasMotivation"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="forceUsedTypeCode" select=".//jxdm:ForceTypeCode"/>
			<xsl:if test="$forceUsedTypeCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Force Used Type Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$forceUsedTypeCode">
							<xsl:value-of select="$forceUsedTypeCode"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="entryPoint" select=".//jxdm:IncidentEntryPoint"/>
			<xsl:if test="$entryPoint">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Incident Entry Point</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$entryPoint">
							<xsl:value-of select="$entryPoint"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="exitPoint" select=".//jxdm:IncidentExitPoint"/>
			<xsl:if test="$exitPoint">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Incident Exit Point</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$exitPoint">
							<xsl:value-of select="$exitPoint"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

		</xsl:element>
	</xsl:template>

	<!--=====================  SUBJECT TEMPLATE  ========================-->

	<!--	This template creates and populates a table for a Subject. 
	This template calls the "personInfo" template to render the caption,
	and the table rows containing general person info. -->

	<xsl:template match="incident:IncidentSubject">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<xsl:call-template name="personInfo">
				<xsl:with-param name="personNode" select="."/>
				<xsl:with-param name="personCaptionRole"
					select="string(&quot;Subject&quot;)"/>
			</xsl:call-template>
			<xsl:call-template name="primaryContactInfo">
				<xsl:with-param name="primaryContactInfoNode"
					select="jxdm:PrimaryContactInformation[normalize-space(.)]"/>
				<xsl:with-param name="extendedPrimaryContactInfoNode"
					select=".//incident:PrimaryContactInformation"/>
			</xsl:call-template>

			<xsl:if test=".//incident:Residence">
				<xsl:variable name="formattedIncidentAddress">
					<xsl:call-template name="streetAddressFormatter">
						<xsl:with-param name="locationAddressNode"
							select=".//incident:Residence/jxdm:LocationAddress"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:if test="$formattedIncidentAddress">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Residence</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:copy-of select="$formattedIncidentAddress"/>
							<xsl:call-template name="displayMap">
								<xsl:with-param name="address" select="$formattedIncidentAddress"/>
								<xsl:with-param name="mapID" select="generate-id()"/>
							</xsl:call-template>
						</xsl:element>
					</xsl:element>
				</xsl:if>
			</xsl:if>

			<xsl:variable name="subjectArmedWeaponRef"
				select="jxdm:SubjectArmedWeaponReference/@jxdm:ref"/>
			<xsl:variable name="weapon" select="//*[@jxdm:id=$subjectArmedWeaponRef]"/>
			<xsl:if test="$weapon">
				<!--
				<tr>
					<th colspan='2'>Subject Armed</th>
				</tr>
	-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Subject Armed</xsl:text>
					</xsl:element>
				</xsl:element>

				<!--
				<tr>
					<th>Weapon</th>
					<td>Baseball Bat</td>
				</tr>
	-->
				<xsl:variable name="weaponType" select="$weapon/jxdm:PropertyTypeText"/>
				<xsl:if test="$weaponType">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Weapon</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$weaponType"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
				<tr>
					<th>Description</th>
					<td>Baseball bat with worn tape around the handle and Sammy Sosa autograph; appears corked</td>
				</tr>
	-->
				<xsl:variable name="weaponDesc" select="$weapon/jxdm:PropertyDescriptionText"/>
				<xsl:if test="$weaponDesc">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Description</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$weaponDesc"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
				<tr>
					<th>Weapon Usage</th>
					<td>Threatened Apu with it</td>
				</tr>
	-->
				<xsl:variable name="weaponUsage"
					select="$weapon/incident:ExtendedPropertyInformation//incident:PropertyUsageDescription"/>
				<xsl:if test="$weaponUsage">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Weapon Usage</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$weaponUsage"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--======================== VICTIM TEMPLATE ===========================-->

	<!-- 	This template creates and populates a table for a Victim. 
	
	If the victim is a person, this template calls the "personInfo" 
	template to render the caption, and the table rows containing 
	general person info. -->

	<xsl:template match="incident:IncidentVictim">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>

			<xsl:variable name="victimPerson" select="incident:Victim.Person"/>
			<xsl:variable name="victimOrganization" select="incident:Victim.Organization"/>

			<xsl:if test="$victimPerson">
				<xsl:call-template name="personInfo">
					<xsl:with-param name="personNode" select="$victimPerson"/>
					<xsl:with-param name="personCaptionRole"
						select="string(&quot;Victim&quot;)"/>
				</xsl:call-template>
			</xsl:if>
			<xsl:call-template name="primaryContactInfo">
				<xsl:with-param name="primaryContactInfoNode"
					select="jxdm:PrimaryContactInformation[normalize-space(.)]"/>
				<xsl:with-param name="extendedPrimaryContactInfoNode"
					select=".//incident:PrimaryContactInformation"/>
			</xsl:call-template>

			<xsl:if test="$victimOrganization">
				<xsl:variable name="orgName" select="$victimOrganization/jxdm:OrganizationName"/>
				<xsl:if test="$orgName">
					<!--
			<tr>
				<th colspan='2' class='group'>Victim Organization</th>
			</tr>
-->
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:attribute name="colspan">2</xsl:attribute>
							<xsl:attribute name="class">group</xsl:attribute>
							<xsl:text>Victim Organization</xsl:text>
						</xsl:element>
					</xsl:element>

					<!--
			<tr>
				<th>Name</th>
				<td>Seven-Eleven</td>
			</tr>
-->
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Name</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:if test="$orgName">
								<xsl:value-of select="$orgName"/>
							</xsl:if>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
			<tr>
				<th>Type</th>
				<td>Convenience Store</td>
			</tr>
-->
				<xsl:variable name="orgType" select="$victimOrganization/jxdm:OrganizationTypeText"/>
				<xsl:if test="$orgType">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Type</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:if test="$orgType">
								<xsl:value-of select="$orgType"/>
							</xsl:if>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
			<tr>
				<th>Street Address</th>
				<td>111 Fifth Avenue<br/>Olympia, WA</td>
			</tr>
-->
				<xsl:variable name="formattedIncidentAddress">
					<xsl:call-template name="streetAddressFormatter">
						<xsl:with-param name="locationAddressNode"
							select="$victimOrganization//jxdm:LocationAddress"/>
					</xsl:call-template>
				</xsl:variable>
				<xsl:if test="$formattedIncidentAddress">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Address</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:copy-of select="$formattedIncidentAddress"/>
							<xsl:call-template name="displayMap">
								<xsl:with-param name="address" select="$formattedIncidentAddress"/>
								<xsl:with-param name="mapID" select="generate-id()"/>
							</xsl:call-template>
						</xsl:element>
					</xsl:element>
				</xsl:if>
			</xsl:if>

			<xsl:variable name="injury" select="jxdm:VictimInjury"/>
			<xsl:if test="$injury">
				<!--
			<tr>
				<th colspan='2'>Injury</th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Injury</xsl:text>
					</xsl:element>
				</xsl:element>

				<xsl:variable name="injuryDesc" select="$injury/jxdm:InjuryDescriptionText"/>
				<xsl:if test="$injuryDesc">
					<!--
			<tr>
				<th>Description</th>
				<td>Financial loss caused by theft of twinkies</td>
			</tr>
-->
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Description</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$injuryDesc"/>
						</xsl:element>
					</xsl:element>

				</xsl:if>

				<xsl:apply-templates select="$injury/jxdm:InjuryCauserReference.Person"/>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--====================== INJURY CAUSER TEMPLATE =======================-->

	<!-- 
	This id a "helper template" for the Victim template.. 
-->
	<xsl:template match="jxdm:InjuryCauserReference.Person">

		<!--
			<tr>
				<th>Caused By</th>
				<td>Bart Simpson</td>
			</tr>
-->
		<xsl:element name="tr">
			<!-- extract the reference identifier from the current "Arrest" context and stash it in the variable -->
			<xsl:variable name="causerRef" select="./@jxdm:ref"/>
			<!-- use the identifier to find the referenced subject node (wherever it is in the document, hence the "//*"
				construct), then get the subject's PersonName subnode -->
			<xsl:variable name="causer" select="//*[@jxdm:id=$causerRef]/jxdm:PersonName"/>
			<xsl:element name="th">
				<xsl:text>Caused By</xsl:text>
			</xsl:element>
			<xsl:element name="td">
				<xsl:if test="$causer">
					<xsl:call-template name="personFullNameResolver">
						<xsl:with-param name="personNameNode" select="$causer"/>
					</xsl:call-template>
				</xsl:if>
			</xsl:element>
		</xsl:element>

	</xsl:template>

	<!--========================  WITNESS TEMPLATE  ==========================-->

	<!-- 
	This template creates and populates a table for a Witness. 
	
	This template calls the "personInfo" 
	template to render the caption, and the table rows containing 
	general person info. 
-->
	<xsl:template match="incident:IncidentWitness">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<xsl:call-template name="personInfo">
				<xsl:with-param name="personNode" select="."/>
				<xsl:with-param name="personCaptionRole"
					select="string(&quot;Witness&quot;)"/>
			</xsl:call-template>

			<xsl:variable name="contactInfo" select=".//incident:PrimaryContactInformation"/>
			<xsl:if test="$contactInfo">
				<!--
			<tr>
				<th colspan='2'>Contact Information</th>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Contact Information</xsl:text>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<td colspan='2'>Contact info for law enforcement use only</td>
			</tr>
-->
				<xsl:variable name="usageDesc"
					select="$contactInfo//incident:TelephoneNumberUsageDescriptionText"/>
				<xsl:if test="$usageDesc">
					<xsl:element name="tr">
						<xsl:element name="td">
							<xsl:attribute name="colspan">2</xsl:attribute>
							<xsl:value-of select="$usageDesc"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<!--
			<tr>
				<th>Telephone Number</th>
				<td>360-555-1212</td>
			</tr>
-->
				<xsl:variable name="phoneNum" select="$contactInfo//jxdm:TelephoneNumberFullID"/>
				<xsl:if test="$phoneNum">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Telephone Number</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$phoneNum"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

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

	<!--================= INVOLVED PERSON TEMPLATE =====================-->

	<!-- 
	This template creates and populates a table for an Involved Person. 
	
	This template calls the "personInfo" 
	template to render the caption, and the table rows containing 
	general person info. 
-->
	<xsl:template match="incident:IncidentPersonInvolvement">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<xsl:call-template name="personInfo">
				<xsl:with-param name="personNode" select="."/>
				<xsl:with-param name="personCaptionRole"
					select="string(&quot;Involved Person&quot;)"/>
			</xsl:call-template>

			<!--
			<tr>
				<th colspan='2'>Involvement</th>
			</tr>
-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:text>Involvement</xsl:text>
				</xsl:element>
			</xsl:element>


			<xsl:variable name="involvement" select="incident:PersonInvolvementDescriptionText"/>
			<xsl:if test="$involvement">
				<!--
			<tr>
				<th>Description</th>
				<td>Met with Bart Simpson earlier in the day, and may have information about his crazed state of mind</td>
			</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Description</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$involvement"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--===============INVOLVED PROPERTY TEMPLATE ==================-->

	<!-- 
	This template creates and populates a table for any Involved Property. 
-->
	<xsl:template match="incident:IncidentInvolvedProperty">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>

			<!--
		<tr>
			<th colspan='2' class='group'>Item: Snack Food</th>
		</tr>
-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Item</xsl:text>
					<xsl:variable name="typeText" select="jxdm:PropertyTypeText"/>
					<xsl:if test="$typeText">
						<xsl:text>: </xsl:text>
						<xsl:value-of select="$typeText"/>
					</xsl:if>
				</xsl:element>
			</xsl:element>

			<!--
		<tr>
			<th>Description</th>
			<td>Large box of Twinkies</td>
		</tr>
-->
			<xsl:variable name="descriptionText" select="jxdm:PropertyDescriptionText"/>
			<xsl:if test="$descriptionText">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Description</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$descriptionText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
		<tr>
			<th>Value</th>
			<td>$2.49</td>
		</tr>
-->
			<xsl:variable name="propertyValue" select=".//jxdm:PropertyValueAmount"/>
			<xsl:if test="$propertyValue">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Value</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$propertyValue"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--=================INVOLVED STRUCTURES TEMPLATE   ========================-->

	<!-- 
	This template creates and populates a table for any Involved Structure. 
-->
	<xsl:template match="incident:IncidentInvolvedStructure">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<!--
			<tr>
				<th colspan='2' class='group'>Structure</th>
			</tr>
-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Structure</xsl:text>
				</xsl:element>
			</xsl:element>

			<!--
			<tr>
				<th>Description</th>
				<td>Seven-Eleven Convenience Store</td>
			</tr>
-->
			<xsl:variable name="descriptionText" select="jxdm:PropertyDescriptionText"/>
			<xsl:if test="$descriptionText">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Description</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$descriptionText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--======================== INVOLVED WEAPONS TEMPLATE  ======================-->

	<!-- 
	This template creates and populates a table for any Involved Weapon. 
-->
	<xsl:template match="incident:IncidentInvolvedWeapon">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<!--
			<tr>
				<th colspan='2' class='group'>Weapon: Baseball bat</th>
			</tr>
-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Weapon</xsl:text>
					<xsl:variable name="typeText" select="jxdm:PropertyTypeText"/>
					<xsl:if test="$typeText">
						<xsl:text>: </xsl:text>
						<xsl:value-of select="$typeText"/>
					</xsl:if>
				</xsl:element>
			</xsl:element>


			<!--
			<tr>
				<th>Description</th>
				<td>Baseball bat with worn tape around the handle and Sammy Sosa autograph; appears corked</td>
			</tr>
-->
			<xsl:variable name="descriptionText" select="jxdm:PropertyDescriptionText"/>
			<xsl:if test="$descriptionText">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Description</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$descriptionText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>


			<!--
			<tr>
				<th colspan='2' class='group'>Usage: Bart Simpson</th>
			</tr>
-->
			<xsl:variable name="usage" select=".//incident:PropertyUsage"/>

			<xsl:variable name="userRef"
				select="$usage/incident:PropertyUsedByPersonReference/@jxdm:ref"/>
			<xsl:variable name="user" select="//*[@jxdm:id=$userRef]/jxdm:PersonName"/>
			<xsl:if test="$usage">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Usage</xsl:text>
						<xsl:if test="$user">
							<xsl:text>: </xsl:text>
							<xsl:call-template name="personFullNameResolver">
								<xsl:with-param name="personNameNode" select="$user"/>
							</xsl:call-template>
						</xsl:if>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<th>Usage In Incident</th>
				<td>Threatened Apu with it</td>
			</tr>
-->
				<xsl:variable name="usageDescriptionText"
					select="$usage/incident:PropertyUsageDescription"/>
				<xsl:if test="$usageDescriptionText">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Usage In Incident</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$usageDescriptionText"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--================== INVOLVED FIREARMS TEMPLATE ========================-->

	<!-- 
	This template creates and populates a table for any Involved Firearms. 
-->
	<xsl:template match="incident:IncidentInvolvedFirearm">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<!--
			<tr>
				<th colspan='2' class='group'>Firearm</th>
			</tr>
-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Firearm</xsl:text>
				</xsl:element>
			</xsl:element>

			<!--
			<tr>
				<th colspan='2' class='group'>Usage: Bart Simpson</th>
			</tr>
-->
			<xsl:variable name="usage" select=".//incident:PropertyUsage"/>

			<xsl:variable name="userRef"
				select="$usage/incident:PropertyUsedByPersonReference/@jxdm:ref"/>
			<xsl:variable name="user" select="//*[@jxdm:id=$userRef]/jxdm:PersonName"/>
			<xsl:if test="$usage">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Usage</xsl:text>
						<xsl:if test="$user">
							<xsl:text>: </xsl:text>
							<xsl:call-template name="personFullNameResolver">
								<xsl:with-param name="personNameNode" select="$user"/>
							</xsl:call-template>
						</xsl:if>
					</xsl:element>
				</xsl:element>

				<!--
			<tr>
				<th>Usage In Incident</th>
				<td>Threatened Apu with it</td>
			</tr>
-->
				<xsl:variable name="descriptionText"
					select="$usage/incident:PropertyUsageDescription"/>
				<xsl:if test="$descriptionText">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Usage In Incident</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$descriptionText"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--===============   INVOLVED VEHICLES TEMPLATE  =================-->

	<!-- 	This template creates and populates a table for any Involved Vehicles. -->

	<xsl:template match="incident:IncidentInvolvedVehicle">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<!--
		<tr>
			<th colspan='2' class='group'>Vehicle: Simpson family automobile</th>
		</tr>
-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Vehicle</xsl:text>
					<xsl:variable name="vehicleDesc" select="jxdm:PropertyDescriptionText"/>
					<xsl:if test="$vehicleDesc">
						<xsl:text>: </xsl:text>
						<xsl:value-of select="$vehicleDesc"/>
					</xsl:if>
				</xsl:element>
			</xsl:element>

			<!--
		<tr>
			<th>Year, Make, Model</th>
			<td>1995 CHEV CHEV-CAP</td>
		</tr>
-->
			<xsl:variable name="vin" select="normalize-space(jxdm:VehicleID)"/>
			<xsl:if test="$vin">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Vehicle Identification Number</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$vin"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Year, Make, Model</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:variable name="year" select="jxdm:VehicleModelYearDate"/>
					<xsl:variable name="make" select="jxdm:VehicleMakeCode"/>
					<xsl:variable name="model" select="jxdm:VehicleModelCode"/>
					<xsl:value-of select="$year"/>
					<xsl:text> </xsl:text>
					<xsl:value-of select="$make"/>
					<xsl:text> </xsl:text>
					<xsl:value-of select="$model"/>
				</xsl:element>
			</xsl:element>

			<xsl:variable name="regInfo" select="jxdm:VehicleRegistration"/>
			<xsl:if test="$regInfo">
				<!--
		<tr>
			<th>Registered in</th>
			<td>MI</td>
		</tr>
	-->
				<xsl:if
					test="boolean(string-length($regInfo/jxdm:RegistrationJurisdictionCode.fips5-2Alpha) &gt; 0)">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Registered State</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of
								select="$regInfo/jxdm:RegistrationJurisdictionCode.fips5-2Alpha"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>
				<!--
		<tr>
			<th>Plate</th>
			<td>123ABC</td>
		</tr>
	-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Registration Plate ID</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$regInfo/jxdm:VehicleRegistrationPlateID"/>
					</xsl:element>
				</xsl:element>

				<xsl:variable name="RegistrationPlateTypeCode"
					select="jxdm:VehicleRegistration/jxdm:VehicleRegistrationPlateTypeCode[normalize-space()]"/>
				<!-- display row only if element is  found and it's not empty  -->
				<xsl:if test="$RegistrationPlateTypeCode">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Registration Plate Type Code</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$RegistrationPlateTypeCode"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

			</xsl:if>

			<xsl:variable name="primaryColorCode" select="jxdm:VehicleColorPrimaryCode"/>
			<xsl:variable name="primaryColorText" select="jxdm:VehicleColorPrimaryText "/>
			<xsl:if test="$primaryColorCode or $primaryColorText">
				<!--
		<tr>
			<th>Primary Color</th>
			<td>RED</td>
		</tr>
-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Primary Color code/text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$primaryColorCode"/>
						<xsl:if test="string-length($primaryColorText) &gt; 0 and string-length($primaryColorCode) &gt; 0 ">
							<xsl:text> / </xsl:text>
						</xsl:if>
						<xsl:value-of select="$primaryColorText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="secondaryColorCode" select="jxdm:VehicleColorSecondaryCode"/>
			<xsl:variable name="secondaryColorText" select="jxdm:VehicleColorSecondaryText"/>
			<xsl:if test="$secondaryColorCode or $secondaryColorText">
				<!--
				<tr>
				<th>Secondary Color</th>
				<td>RED</td>
				</tr>
			-->
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Secondary Color code/text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$secondaryColorCode"/>
						<xsl:if test="string-length($secondaryColorText) &gt; 0 and string-length($secondaryColorCode)&gt; 0 ">
							<xsl:text> / </xsl:text>
						</xsl:if>
						<xsl:value-of select="$secondaryColorText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="vehicleModelCodeText"
				select="jxdm:VehicleModelCodeText[normalize-space()]"/>
			<xsl:if test="boolean(string-length($vehicleModelCodeText) &gt; 0)">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Model Code Text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$vehicleModelCodeText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="vehicleStyleCode" select="jxdm:VehicleStyleCode[normalize-space()]"/>
			<xsl:if test="boolean(string-length($vehicleStyleCode) &gt; 0)">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Style Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$vehicleStyleCode"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
			<!--
			<tr>
				<th colspan='2' class='group'>Usage: Bart Simpson</th>
			</tr>
-->
			<xsl:variable name="usage" select=".//incident:PropertyUsage"/>

			<xsl:variable name="userRef"
				select="$usage/incident:PropertyUsedByPersonReference/@jxdm:ref"/>
			<xsl:variable name="user" select="//*[@jxdm:id=$userRef]/jxdm:PersonName"/>
			<xsl:if test="$usage">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:text>Usage</xsl:text>
						<xsl:if test="$user">
							<xsl:text>: </xsl:text>
							<xsl:call-template name="personFullNameResolver">
								<xsl:with-param name="personNameNode" select="$user"/>
							</xsl:call-template>
						</xsl:if>
					</xsl:element>
				</xsl:element>


				<!--
			<tr>
				<th>Usage In Incident</th>
				<td>Planned getaway in it</td>
			</tr>
-->
			</xsl:if>
			<!--
			<tr>
				<th colspan='2' class='group'>Usage: Homer Simpson</th>
			</tr>
-->

			<!--
			<tr>
				<th>Usage In Incident</th>
				<td>Fled in it</td>
			</tr>
-->
		</xsl:element>
	</xsl:template>

	<!--==================== INVOLVED DRUGS TEMPLATE  ======================-->

	<!-- 
	This template creates and populates a table for any Involved Drugs. 
-->
	<xsl:template match="incident:IncidentInvolvedDrug">
		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<!--
		<tr>
			<th colspan='2' class='group'>Drugs</th>
		</tr>
-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Drugs</xsl:text>
				</xsl:element>
			</xsl:element>

			<!--
		<tr>
			<th>Drug Type Code</th>
			<td>1.25 OZ</td>
		</tr>
-->
			<xsl:variable name="drugTypeCode" select="jxdm:DrugTypeCode"/>
			<xsl:if test="$drugTypeCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Drug Type Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$drugTypeCode"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
		<tr>
			<th>Amount</th>
			<td>1.25 OZ</td>
		</tr>
-->
			<xsl:variable name="drugAmount" select="jxdm:DrugQuantityMeasure"/>
			<xsl:if test="$drugAmount">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Amount</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$drugAmount"/>
						<xsl:text> </xsl:text>
						<xsl:value-of select="$drugAmount/@jxdm:drugUnitCode"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
		</xsl:element>
	</xsl:template>

	<!--================PERSON TEMPLATE   ======================-->

	<!-- This template creates table rows for a Person. The assumption
	is that the table in which the rows are written has already been 
	created by the calling template. -->
	<xsl:template name="personInfo">
		<!-- parameter "personNode" is the node representing the person.
		If it is not provided, this template returns nothing. -->
		<xsl:param name="personNode"/>
		<!-- parameter "personCaptionRole" is a string node containing
		the beginning of the person's caption header, usually
		describing a role of some sort: "Subject", "Witness" etc. 
		If not provided, no caption role will be created. -->
		<xsl:param name="personCaptionRole"/>

		<xsl:if test="$personNode">
			<xsl:variable name="givenName"
				select="$personNode//jxdm:PersonName/jxdm:PersonGivenName"/>
			<xsl:variable name="surName" select="$personNode//jxdm:PersonName/jxdm:PersonSurName"/>
			<xsl:variable name="middleName"
				select="$personNode//jxdm:PersonName/jxdm:PersonMiddleName"/>
			<xsl:variable name="rawFullName"
				select="$personNode//jxdm:PersonName/jxdm:PersonFullName[not(@xsi:nil)]"/>

			<xsl:variable name="fullName">
				<xsl:call-template name="personFullNameResolver">
					<xsl:with-param name="personNameNode" select="$personNode//jxdm:PersonName"/>
				</xsl:call-template>
			</xsl:variable>

			<xsl:variable name="caption">
				<xsl:if test="$personCaptionRole">
					<xsl:value-of select="$personCaptionRole"/>
				</xsl:if>
				<xsl:if test="$personCaptionRole and $fullName">
					<xsl:text>: </xsl:text>
				</xsl:if>
				<xsl:if test="$fullName">
					<xsl:value-of select="$fullName"/>
				</xsl:if>
			</xsl:variable>

			<!-- for testing only: DELETE THIS when no longer needed -->
			<!--<xsl:element name='tr'>
						<xsl:element name='td'>
							<xsl:attribute name='colspan'>2</xsl:attribute>
							
							<xsl:value-of select='$personNode' />
							<xsl:element name="br"/>
							<xsl:if test='$rawFullName'>
								<xsl:text>rawFullName is true!</xsl:text>
							</xsl:if>
							<xsl:element name="br"/>
							<xsl:if test='$fullName'>
								<xsl:text>fullName is true!</xsl:text>
							</xsl:if>
						</xsl:element>
					</xsl:element>-->

			<!--
				<tr>
					<th colspan='2' class='group'>Subject Bart Simpson</th>
				</tr>
	-->
			<xsl:if test="$caption">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:value-of select="$caption"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>


			<!--
				<tr>
					<th>Given Name</th>
					<td>Bart</td>
				</tr>
	-->
			<xsl:if test="$givenName">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Given Name</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$givenName"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
				<tr>
					<th>Surname</th>
					<td>Simpson</td>
				</tr>
	-->
			<xsl:if test="$surName">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Surname</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$surName"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:if test=" $middleName">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Middlename</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select=" $middleName"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
				<tr>
					<th>Full Name</th>
					<td>Bart Simpson</td>
				</tr>
	-->
			<!-- we only display this if it was provided in the source document -->
			<xsl:if test="($rawFullName)">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Full Name</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$rawFullName"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>


			<xsl:variable name="aka" select="$personNode//jxdm:PersonAlternateName"/>
			<xsl:if test="$aka">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>AKA</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:call-template name="personFullNameResolver">
							<xsl:with-param name="personNameNode" select="$aka"/>
						</xsl:call-template>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
				<tr>
					<th>Age (estimated)</th>
					<td>10 yr</td>
					</tr>-->
			<xsl:variable name="birthDate" select="$personNode//jxdm:PersonBirthDate"/>
			<xsl:if test="($birthDate)">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Birth Date</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$birthDate"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="ageMeasure" select="$personNode/jxdm:PersonAgeMeasure"/>
			<xsl:if test="boolean(string-length($ageMeasure) &gt; 0)">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Age</xsl:text>
						<xsl:if test="$ageMeasure/@jxdm:measurementEstimatedIndicator">
							<xsl:text> (estimated)</xsl:text>
						</xsl:if>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$ageMeasure"/>
						<xsl:text> </xsl:text>
						<xsl:value-of select="$ageMeasure/@jxdm:ageUnitCode"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
			<!--
				<tr>
					<th>Height</th>
					<td>50 units</td>
				</tr>
	-->
			<xsl:variable name="heightMeasure" select="$personNode//jxdm:PersonHeightMeasure"/>
			<xsl:variable name="heightDescriptionTextFlag"
				select="boolean(string-length($personNode//jxdm:PersonHeightDescriptionText/normalize-space(text())) &gt; 0)"/>
			<xsl:if test="$heightMeasure">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Height</xsl:text>
						<xsl:if
							test="$heightMeasure/@jxdm:measurementEstimatedIndicator or $heightDescriptionTextFlag ">
							<xsl:text> (estimated)</xsl:text>
						</xsl:if>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$heightMeasure"/>
						<xsl:if
							test="$heightMeasure/@jxdm:measurementEstimatedIndicator or $heightDescriptionTextFlag">
							<xsl:text>&#x9;</xsl:text>
							<xsl:if
								test="string-length($heightMeasure/@jxdm:measureUnitText) &gt;0">
								<xsl:value-of select="$heightMeasure/@jxdm:measureUnitText"/>
							</xsl:if>
							<xsl:if test="$heightDescriptionTextFlag ">
								<xsl:text>&#x9;</xsl:text>
								<xsl:value-of select="$personNode//jxdm:PersonHeightDescriptionText"
								/>
							</xsl:if>

						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="weight" select="$personNode//jxdm:PersonWeightMeasure"/>
			<xsl:variable name="weightDescriptionText"
				select="$personNode//jxdm:PersonWeightDescriptionText/normalize-space(text())"/>
			<xsl:if test="string-length($weight) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Weight</xsl:text>
						<xsl:if test="$weightDescriptionText">
							<xsl:text> (estimated)</xsl:text>
						</xsl:if>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$weight"/>
						<xsl:if test="string-length($weightDescriptionText) &gt; 0">
							<xsl:text>&#x9;</xsl:text>
							<xsl:value-of select="$weightDescriptionText"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
				<tr>
					<th>Hair</th>
					<td>BLN</td>
				</tr>
	-->
			<xsl:variable name="hairColorCode"
				select="$personNode//jxdm:PersonHairColorCode/normalize-space(text())"/>
			<xsl:variable name="hairColorText"
				select="$personNode//jxdm:PersonHairColorText/normalize-space(text())"/>
			<xsl:if
				test="string-length($hairColorCode) &gt; 0 or string-length ($hairColorText)&gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Hair Color code/text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$hairColorCode"/>
						<xsl:if
							test="string-length($hairColorCode) &gt; 0 and string-length($hairColorText) &gt; 0">
							<xsl:text> / </xsl:text>
						</xsl:if>
						<xsl:value-of select="$hairColorText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="personHairLength"
				select="$personNode//jxdm:PersonHairLengthText[normalize-space()]"/>
			<xsl:if test="string-length($personHairLength) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Hair Length Text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$personHairLength"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="personHairStyleText"
				select="$personNode//jxdm:PersonHairStyleText[normalize-space()]"/>
			<xsl:if test="string-length($personHairStyleText) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Hair Style Text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$personHairStyleText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
				<tr>
					<th>Eye Color</th>
					<td>BLU</td>
				</tr>
	-->

			<xsl:call-template name="PersonEyeDetails">
				<xsl:with-param name="eyeColorCode" select="$personNode//jxdm:PersonEyeColorCode"/>
				<xsl:with-param name="eyeColorText" select="$personNode//jxdm:PersonEyeColorText"/>
			</xsl:call-template>
			<!--
				<tr>
					<th>Sex</th>
					<td>M</td>
				</tr>
	-->
			<xsl:variable name="sexCode"
				select="$personNode//jxdm:PersonSexCode/normalize-space(text())"/>
			<xsl:variable name="sexText"
				select="$personNode//jxdm:PersonSexText/normalize-space(text())"/>
			<xsl:if test="string-length($sexCode) &gt; 0 or string-length($sexText) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Sex code/text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$sexCode"/>
						<xsl:if
							test="string-length($sexCode) &gt; 0 and string-length($sexText) &gt; 0">
							<xsl:text> / </xsl:text>
						</xsl:if>
						<xsl:value-of select="$sexText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="raceCode"
				select="$personNode//jxdm:PersonRaceCode/normalize-space(text())"/>
			<xsl:variable name="raceText"
				select="$personNode//jxdm:PersonRaceText/normalize-space(text())"/>
			<xsl:if
				test="string-length($raceCode) &gt; 0 or string-length($raceText) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Race code/text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$raceCode"/>
						<xsl:if
							test="string-length($raceCode) &gt; 0 and string-length($raceText) &gt; 0">
							<xsl:text> / </xsl:text>
						</xsl:if>
						<xsl:value-of select="$raceText"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="skinToneCode"
				select="$personNode//jxdm:PersonSkinToneCode[normalize-space()]"/>
			<xsl:if test="$skinToneCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Skin Tone  Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$skinToneCode"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--
				<tr>
					<th>Ethnicity</th>
					<td>N</td>
				</tr>
	-->
			<xsl:variable name="ethnicityCode" select="$personNode//jxdm:PersonEthnicityCode"/>
			<xsl:variable name="ethnicitytext" select="$personNode//jxdm:PersonEthnicityText"/>
			<xsl:if test="boolean(string-length($ethnicityCode) &gt; 0 or string-length($ethnicitytext) &gt; 0)">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Ethnicity code/text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$ethnicityCode"/>
						<xsl:if test="string-length($ethnicityCode) &gt; 0 and string-length($ethnicitytext) &gt; 0">
							<xsl:text> / </xsl:text>
						</xsl:if>
						<xsl:value-of select="$ethnicitytext"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
			
			<!--
				<tr>
					<th>Language Code</th>
					<td>eng</td>
				</tr>
	        -->
			<xsl:variable name="primaryLanguage"
				select="$personNode//jxdm:PersonPrimaryLanguageCode.iso639-2b"/>
			<xsl:if test="string-length(normalize-space($primaryLanguage)) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Primary Language</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$primaryLanguage"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!--<xsl:variable name='ssnID' select='$personNode//jxdm:PersonSSNID[normalize-space(@jxdm:id)]' />  there are sending it as 
			 <j:PersonSSNID>
			      <j:ID>477-86-1007</j:ID>
			 </j:PersonSSNID>
		       so I have to change the path -->

			<xsl:variable name="ssnID"
				select="$personNode//jxdm:PersonSSNID/jxdm:ID[normalize-space()]"/>
			<xsl:if test="string-length(normalize-space($ssnID) ) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>SSN ID</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$ssnID"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!-- If local agencies are sending node like 
			<PersonDriverLicenseID>
				<ID/>
			</PersonDriverLicenseID>
			 we are showing blank for Driver License ID. To avoid that changed  Xpath to be 
			 $personNode//jxdm:PersonDriverLicenseID/jxdm:ID from $personNode//jxdm:PersonDriverLicenseID
		-->

			<xsl:variable name="personDriverLicenseID"
				select="$personNode//jxdm:PersonDriverLicenseID/jxdm:ID"/>
			<xsl:if test="string-length(normalize-space($personDriverLicenseID)) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Driver License ID</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$personDriverLicenseID"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:variable name="personsFBIID"
				select="$personNode//jxdm:PersonFBIID/jxdm:ID[normalize-space()]"/>
			<xsl:if test="string-length(normalize-space($personsFBIID)) &gt; 0">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>FBI ID</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$personsFBIID"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<!-- According to valid JXDM Schema for a person only one "PersonPhysicalFeature" node will be thier. 
			So removed for each loop. See Mashesh Adduri for further details
			<xsl:for-each select=".//incident:PersonPhysicalFeature">-->

			<xsl:call-template name="physicalfeatures">
				<xsl:with-param name="personNode" select="."/>
				<xsl:with-param name="physicalFeatureTypeCode"
					select=".//jxdm:PhysicalFeatureTypeCode[normalize-space()]"/>
				<xsl:with-param name="physicalFeatureDescription"
					select=".//jxdm:PhysicalFeatureDescriptionText[normalize-space()]"/>
			</xsl:call-template>

			<!--</xsl:for-each>-->
			<xsl:apply-templates select="$personNode//incident:ExtendedPersonInformation//incident:PersonDigitalImage"></xsl:apply-templates>
		</xsl:if>
	</xsl:template>

	<!--=================NODE BY REFERENCE RESOLUTION TEMPLATE ========================-->

	<!-- This template retrieves a Node when passed a jxdm:id value -->
	<xml:template name="nodeFromReference">
		<xsl:param name="jxdmRef"/>
		<xsl:copy-of select="//*[@jxdm:id=$jxdmRef]"/>
	</xml:template>

	<!--==================== PERSON FULL NAME RESOLUTION TEMPLATE ======================-->
	<!--                             -->

	<!-- This template retrieves a "full name" text representation from a Person 
	Name Node -->
	<xsl:template name="personFullNameResolver">
		<xsl:param name="personNameNode"/>

		<xsl:if test="$personNameNode">
			<xsl:variable name="givenName"
				select="$personNameNode//jxdm:PersonGivenName[normalize-space()]"/>
			<xsl:variable name="surName"
				select="$personNameNode//jxdm:PersonSurName[normalize-space()]"/>
			<xsl:variable name="middleName"
				select="$personNameNode//jxdm:PersonMiddleName[normalize-space()]"/>
			<xsl:variable name="rawFullName"
				select="$personNameNode//jxdm:PersonFullName[normalize-space()]"/>

			<xsl:choose>
				<xsl:when test="$rawFullName">
					<xsl:value-of select="$rawFullName"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="$givenName">
						<xsl:value-of select="$givenName"/>
					</xsl:if>

					<xsl:if test="$middleName">
						<xsl:text> </xsl:text>
						<xsl:value-of select="$middleName"/>
					</xsl:if>
					<xsl:if test="$surName">
						<xsl:text> </xsl:text>
						<xsl:value-of select="$surName"/>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<!--=====================TELEPHONENUMBER FULL ID RESOLUTION TEMPLATE=====================-->

	<!-- This template retrieves a "full ID" text representation from a TELEPHONENUBMER Node -->
	<xsl:template name="telephoneFullIDResolver">
		<xsl:param name="telephoneNumberNode"/>

		<xsl:if test="$telephoneNumberNode">
			<xsl:variable name="areaCode"
				select="$telephoneNumberNode/jxdm:TelephoneAreaCodeID[normalize-space()]"/>
			<xsl:variable name="subscirberID"
				select="$telephoneNumberNode/jxdm:TelephoneSubscriberID[normalize-space()]"/>
			<xsl:variable name="suffixID"
				select="$telephoneNumberNode/jxdm:TelephoneSuffixID[normalize-space()]"/>
			<xsl:variable name="rawfullID"
				select="$telephoneNumberNode/jxdm:TelephoneNumberFullID[normalize-space()]"/>

			<xsl:choose>
				<xsl:when test="$rawfullID">
					<xsl:value-of select="$rawfullID"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="$areaCode">
						<xsl:value-of select="$areaCode"/>
					</xsl:if>

					<xsl:if test="$subscirberID">
						<xsl:text> </xsl:text>
						<xsl:value-of select="$subscirberID"/>
					</xsl:if>
					<xsl:if test="$suffixID">
						<xsl:text> </xsl:text>
						<xsl:value-of select="$suffixID"/>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<!--===================== STREET ADDRESS RESOLUTION TEMPLATE ========================-->

	<!-- This template retrieves a "full ID" text representation from a TELEPHONENUBMER Node -->
	<xsl:template name="streetAddressResolver">
		<xsl:param name="locationStreet"/>

		<xsl:if test="$locationStreet[normalize-space()]">
			<xsl:variable name="rawFullText"
				select="$locationStreet/jxdm:StreetFullText[normalize-space()]"/>
			<xsl:variable name="streetNumber"
				select="$locationStreet/jxdm:StreetNumber[normalize-space()]"/>
			<xsl:variable name="streetName"
				select="$locationStreet/jxdm:StreetName[normalize-space()]"/>

			<xsl:choose>
				<xsl:when test="$rawFullText">
					<xsl:value-of select="$rawFullText"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="$streetNumber">
						<xsl:value-of select="$streetNumber"/>
					</xsl:if>

					<xsl:if test="$streetName">
						<xsl:text> </xsl:text>
						<xsl:value-of select="$streetName"/>
					</xsl:if>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<!--============ STREET ADDRESS DISPLAY/FORMATTING TEMPLATE ============-->


	<!-- Given a jxdm:LocationAddress node, this template returns a
	simple formatted text representation. Behavior if a different kind of
	node is passed is not guaranteed. -->
	<!-- Usage tip: when calling this template and putting its result into a variable,
	use xsl:copy-of rather than xsl:value-of to insert the variable into 
	the result tree, so that the <br/> element won't get stripped out. -->
	<xsl:template name="streetAddressFormatter">
		<xsl:param name="locationAddressNode"/>

		<xsl:if test="$locationAddressNode">
			<xsl:variable name="rawFullText"
				select="$locationAddressNode/jxdm:AddressFullText[normalize-space()]"/>
			<xsl:variable name="streetAddressText">
				<xsl:call-template name="streetAddressResolver">
					<xsl:with-param name="locationStreet"
						select="$locationAddressNode/jxdm:LocationStreet"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:variable name="city"
				select="$locationAddressNode/jxdm:LocationCityName[normalize-space()]"/>
			<xsl:variable name="state"
				select="$locationAddressNode/jxdm:LocationStateCode.fips5-2Alpha[normalize-space()]"/>
			<xsl:variable name="stateName"
				select="$locationAddressNode/jxdm:LocationStateName[normalize-space()]"/>
			<xsl:variable name="postalCode"
				select="$locationAddressNode/jxdm:LocationPostalCodeID/jxdm:ID[normalize-space()]"/>

			<xsl:choose>
				<xsl:when test="$rawFullText">
					<xsl:value-of select="$rawFullText"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:if test="$streetAddressText">
						<xsl:value-of select="$streetAddressText"/>
					</xsl:if>
					<xsl:if
						test="$streetAddressText and ($city or $state or $stateName or $postalCode)">
						<xsl:text>&#x9;</xsl:text>
						<!--<xsl:text>&#xA; </xsl:text> -->
					</xsl:if>
					<xsl:if test="$city">
						<xsl:value-of select="$city"/>
					</xsl:if>
					<xsl:if test="$city and $state or $stateName or $postalCode">
						<xsl:text>, </xsl:text>
					</xsl:if>

					<xsl:choose>
						<xsl:when test="$state">
							<xsl:value-of select="$state"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:if test="$stateName">
								<xsl:value-of select="$stateName"/>
							</xsl:if>
						</xsl:otherwise>
					</xsl:choose>
					<xsl:if test="$postalCode">
						<xsl:text> </xsl:text>
						<xsl:value-of select="$postalCode"/>
					</xsl:if>


				</xsl:otherwise>
			</xsl:choose>
		</xsl:if>
	</xsl:template>

	<!-- "pass-through" preservation of certain HTML elements
	and attributes, unaltered, from the source document.
	This is included in case the IEPD is provided
	with HTML markup in the text fields. 
	
	Add new elements as required.
-->
	<xsl:template match="a|p|ul|ol|li|code|b|strong|i|em|span|br|pre">
		<xsl:copy>
			<xsl:copy-of select="@*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

	<!--====================Recursively Show Not Null Nodes TEMPLATE =========================-->

	<!-- Given a not null node, this template returns a fommated output of the node and it's 
        not null children. -->
	<xsl:template name="showNotNullNodesRecursively">
		<xsl:param name="currentNode"/>

		<xsl:if test="$currentNode">
			<xsl:call-template name="showNotNullNodes">
				<xsl:with-param name="currentNode" select="$currentNode"/>
			</xsl:call-template>

			<xsl:for-each select="$currentNode/*[(count(node()) > 1)]">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:attribute name="colspan">2</xsl:attribute>
						<xsl:attribute name="class">group</xsl:attribute>
						<xsl:value-of select="local-name(.)"/>
					</xsl:element>
				</xsl:element>
				<xsl:call-template name="showNotNullNodesRecursively">
					<xsl:with-param name="currentNode" select="."/>
				</xsl:call-template>
			</xsl:for-each>

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

	<!--================== Show Not Null Nodes TEMPLATE =======================-->

	<!-- Given a not null node, this template returns a fommated output of the this node and it's 
	not children which have only a text element child. -->
	<xsl:template name="showNotNullNodes">
		<xsl:param name="currentNode"/>

		<xsl:if test="$currentNode">
			<!-- This count(descendant::node()) test will behave deferrently on xslt2.0 and xslt1.0
			Using xslt2.0, the statement should be count(descendant::node()) = 1
			Using xslt1.0, the statement should be count(descendant::node()) = 0
		         The purpose is to get the node set which doesn't have child element. 
		         For example: <personFullName>fullName</personFullName> qualifies. 
		                      while<personFullName>
		                      	<personSurName>Wei</personSurname>
		                      	<personFirstName></personFirstName>
		                              </personFullName>
		                              doesn't qualify. 
		 -->
			<xsl:for-each select="$currentNode/*[(count(descendant::node()) = 0) and string(.) ]">
				<xsl:call-template name="showNode">
					<xsl:with-param name="currentNode" select="."/>
				</xsl:call-template>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<!--================ Show CURRENT TEXT NODE TEMPLATE =======================-->

	<!-- Given a not null node, this template returns a fommated output of the this node and it's 
	not children which have only a text element child. -->
	<xsl:template name="showNode">
		<xsl:param name="currentNode"/>

		<xsl:if test="$currentNode">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:value-of select="local-name(.)"/>
				</xsl:element>
				<xsl:element name="td">
					<xsl:value-of select="."/>
				</xsl:element>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<!--================Show Element TEMPLATE ===============================-->

	<!-- Given a not null node, this template returns a fommated output of the this node and it's 
	not children which have only a text element child. -->
	<xsl:template name="showElement">
		<xsl:param name="header"/>
		<xsl:param name="value"/>

		<xsl:if test="normalize-space($header) and normalize-space($value)">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:value-of select="$header"/>
				</xsl:element>
				<xsl:element name="td">
					<xsl:value-of select="$value"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<!--=====================PRIMARY CONTACT INFO TEMPLATE ===================-->

	<!-- Given a not null PRIMARY CONTACT INFO node, this template returns a fommated output of the this node and it's 
	not children which have only a text element child. -->
	<xsl:template name="primaryContactInfo">
		<xsl:param name="primaryContactInfoNode"/>
		<xsl:param name="extendedPrimaryContactInfoNode"/>
		<xsl:if
			test="$primaryContactInfoNode/*[normalize-space(.)] or $extendedPrimaryContactInfoNode/*[normalize-space(.)]">
			<!--
			<tr>
			<th colspan='2'>Contact Information</th>
			</tr>
		-->
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:text>Contact Information</xsl:text>
				</xsl:element>
			</xsl:element>

			<xsl:for-each select="$primaryContactInfoNode/*[count(node())>=1]">
				<xsl:choose>
					<xsl:when test="$primaryContactInfoNode/jxdm:ContactMailingAddress">
						<xsl:call-template name="showNotNullNodes">
							<xsl:with-param name="currentNode" select="."/>
						</xsl:call-template>
						<xsl:variable name="formattedIncidentAddress">
							<xsl:call-template name="streetAddressFormatter">
								<xsl:with-param name="locationAddressNode"
									select=".//jxdm:LocationAddress"/>
							</xsl:call-template>
						</xsl:variable>
						<xsl:if test="$formattedIncidentAddress">
							<xsl:element name="tr">
								<xsl:element name="th">
									<xsl:text>Address</xsl:text>
								</xsl:element>
								<xsl:element name="td">
									<xsl:copy-of select="$formattedIncidentAddress"/>
									<xsl:call-template name="displayMap">
										<xsl:with-param name="address"
											select="$formattedIncidentAddress"/>
										<xsl:with-param name="mapID" select="generate-id()"/>
									</xsl:call-template>
								</xsl:element>
							</xsl:element>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="showNotNullNodesRecursively">
							<xsl:with-param name="currentNode" select="."/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
				<!-- This is contactInfo phonenubmer -->
			</xsl:for-each>

			<xsl:call-template name="extendedPrimaryContactInfo">
				<xsl:with-param name="extendedPrimaryContactInfoNode"
					select="$extendedPrimaryContactInfoNode"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<!--================EXTENDED PRIMARY CONTACT INFO TEMPLATE =======================-->

	<!-- Given a not null PRIMARY CONTACT INFO node, this template returns a fommated output of the this node and it's 
	not children which have only a text element child. -->
	<xsl:template name="extendedPrimaryContactInfo">
		<xsl:param name="extendedPrimaryContactInfoNode"/>
		<xsl:if test="$extendedPrimaryContactInfoNode/*[normalize-space()]">
			<!--
			<tr>
			<th colspan='2'>Contact Information</th>
			</tr>
		-->

			<xsl:for-each select="$extendedPrimaryContactInfoNode/*[normalize-space()]">
				<xsl:choose>
					<xsl:when test="local-name()='ContactPerson'">
						<xsl:element name="tr">
							<xsl:element name="th">
								<xsl:text>Contact Person</xsl:text>
							</xsl:element>
							<xsl:element name="td">
								<xsl:call-template name="personFullNameResolver">
									<xsl:with-param name="personNameNode"
										select="$extendedPrimaryContactInfoNode/incident:ContactPerson/jxdm:PersonName"
									/>
								</xsl:call-template>
							</xsl:element>
						</xsl:element>
					</xsl:when>
					<xsl:when test="local-name()='ContactInformationTelephoneNumberUsage'">
						<xsl:call-template name="phoneNumber">
							<xsl:with-param name="phoneNumberNode" select="."/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="showNotNullNodes">
							<xsl:with-param name="currentNode"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<!--===================== INCIDENT LOCATION TEMPLATE====================-->

	<!-- Given a not null Incident Location node, this template returns a fommated output of the this node and it's 
not children which have only a text element child. -->

	<xsl:template name="locationAddress">
		<xsl:param name="locationAddressNode"/>
		<xsl:if test="$locationAddressNode/*[normalize-space()]">
			<xsl:variable name="formattedIncidentAddress">
				<xsl:call-template name="streetAddressFormatter">
					<xsl:with-param name="locationAddressNode" select="$locationAddressNode"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:if test="$formattedIncidentAddress">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Address</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:copy-of select="$formattedIncidentAddress"/>
						<xsl:call-template name="displayMap">
							<xsl:with-param name="address" select="$formattedIncidentAddress"/>
							<xsl:with-param name="mapID" select="generate-id()"/>
						</xsl:call-template>
					</xsl:element>
				</xsl:element>
			</xsl:if>
		</xsl:if>
	</xsl:template>

	<!--=================== CONTACT INFO  PHONE NUMBER TEMPLATE======================-->

	<!-- Given a not null PRIMARY CONTACT INFO node, this template returns a fommated output of the this node and it's 
	not children which have only a text element child. -->
	<xsl:template name="phoneNumber">
		<xsl:param name="phoneNumberNode"/>
		<xsl:if test="$phoneNumberNode/*[string(.)]">
			<xsl:for-each select="$phoneNumberNode/child::node()[normalize-space()]">
				<xsl:choose>
					<xsl:when test="local-name() = 'TelephoneNumberUsageDescriptionText'">
						<!--
					<tr>
					<td colspan='2'>Contact info for law enforcement use only</td>
					</tr>
				-->
						<xsl:element name="tr">
							<xsl:element name="td">
								<xsl:attribute name="colspan">2</xsl:attribute>
								<xsl:value-of select="."/>
							</xsl:element>
						</xsl:element>
					</xsl:when>

					<!--
					<tr>
					<th>Telephone Number</th>
					<td>360-555-1212</td>
					</tr>
				-->
					<xsl:when test="local-name() = 'TelephoneNumber'">
						<xsl:element name="tr">
							<xsl:element name="th">
								<xsl:text>Telephone Number</xsl:text>
							</xsl:element>
							<xsl:element name="td">
								<xsl:call-template name="telephoneFullIDResolver">
									<xsl:with-param name="telephoneNumberNode" select="."/>
								</xsl:call-template>
							</xsl:element>
						</xsl:element>
					</xsl:when>
					<xsl:otherwise>
						<!-- Verified with Mahesh Under ContactInformationTelephoneNumberUsage node
						there will be only TelephoneNumberUsageDescriptionText and TelephoneNumber
						so jxdm schema does not have any other elements.So commenting out the showNotNullNodesRecursively template.
						<xsl:call-template name="showNotNullNodesRecursively">
						<xsl:with-param name="currentNode" select='.' />
						</xsl:call-template>-->
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<!--=============== ARREST OFFICIAL TEMPLATE ======================-->

	<!-- Given a not null ArrestOfficial INFO node, this template returns a fommated output of the this node and it's 
	not children which have only a text element child. -->
	<xsl:template name="arrestOfficial">
		<xsl:param name="arrestOfficial"/>
		<xsl:if test="$arrestOfficial/*[string(.)]">
			<!--
			<tr>
			<th colspan='2'>Arrest Official</th>
			</tr>
		-->
			<xsl:element name="tr">
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:text> </xsl:text>
				</xsl:element>
			</xsl:element>
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Arrest Official</xsl:text>
				</xsl:element>
			</xsl:element>

			<xsl:call-template name="showNotNullNodes">
				<xsl:with-param name="currentNode" select="$arrestOfficial"/>
			</xsl:call-template>
			<xsl:for-each select="$arrestOfficial/*[count(node())>1]">
				<xsl:choose>
					<xsl:when test="$arrestOfficial/incident:EnforcementOfficialUnit">
						<xsl:call-template name="showNotNullNodes">
							<xsl:with-param name="currentNode" select="."/>
						</xsl:call-template>
						<xsl:if
							test="$arrestOfficial/incident:EnforcementOfficialUnit/incident:ExtendedOrganizationInformation[normalize-space()]">
							<xsl:element name="tr">
								<xsl:element name="th">
									<xsl:attribute name="colspan">2</xsl:attribute>
									<xsl:text>Contact Information</xsl:text>
								</xsl:element>
							</xsl:element>
						</xsl:if>
						<xsl:for-each select="./*[count(node())>=1]">
							<xsl:choose>
								<xsl:when
									test="$arrestOfficial/incident:EnforcementOfficialUnit/incident:ExtendedOrganizationInformation">

									<xsl:call-template name="extendedPrimaryContactInfo">
										<xsl:with-param name="extendedPrimaryContactInfoNode"
											select="./incident:OrganizationPrimaryContact"/>
									</xsl:call-template>
								</xsl:when>
								<xsl:otherwise>
									<xsl:call-template name="showNotNullNodesRecursively">
										<xsl:with-param name="currentNode"
											select="incident:OrganizationPrimaryContact"/>
									</xsl:call-template>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:for-each>
					</xsl:when>

					<!--
					<tr>
					<th>Telephone Number</th>
					<td>360-555-1212</td>
					</tr>
				-->
					<xsl:otherwise>
						<xsl:call-template name="showNotNullNodesRecursively">
							<xsl:with-param name="currentNode" select="."/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<!--=============Template to display physical features of a person ==================-->

	<xsl:template name="physicalfeatures">
		<xsl:param name="personNode"/>
		<xsl:param name="physicalFeatureTypeCode"/>
		<xsl:param name="physicalFeatureDescription"/>
		<xsl:if test="$physicalFeatureTypeCode">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Scars, Marks and Tattoos code</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:value-of select="$physicalFeatureTypeCode"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>
		<xsl:if test="$physicalFeatureDescription">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Scars, Marks and Tattoos text</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:value-of select="$physicalFeatureDescription"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<!--================Template to format time ========================= -->

	<xsl:template name="formatTime">
		<xsl:param name="time"/>
		<xsl:value-of select="substring($time,1,8)"/>
	</xsl:template>

	<!-- =============Incident Report Metadata For Technical Staff=============-->

	<xsl:template name="metadata">
		<xsl:element name="div">
			<xsl:attribute name="class">block</xsl:attribute>

			<xsl:element name="span">
				<xsl:attribute name="class">blockcaption</xsl:attribute>
				<xsl:text>Incident Report Metadata For Technical Staff</xsl:text>
			</xsl:element>

			<xsl:element name="table">
				<xsl:attribute name="class">normal narrow</xsl:attribute>

				<xsl:variable name="activityCrimeCaseSourceIDText"
					select="//jxdm:ActivityCrimeCase/@jxdm:sourceIDText[normalize-space()]"/>
				<xsl:if test="$activityCrimeCaseSourceIDText">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Activity Crime Case Source ID Text</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$activityCrimeCaseSourceIDText"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<xsl:variable name="locationID" select="//incident:IncidentLocation/@jxdm:id"/>
				<xsl:if test="$locationID">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Location  ID</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$locationID"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<xsl:variable name="locationSourceIDText"
					select="//incident:IncidentLocation/@jxdm:sourceIDText"/>
				<xsl:if test="$locationSourceIDText">
					<xsl:element name="tr">
						<xsl:element name="th">
							<xsl:text>Location Source ID Text</xsl:text>
						</xsl:element>
						<xsl:element name="td">
							<xsl:value-of select="$locationSourceIDText"/>
						</xsl:element>
					</xsl:element>
				</xsl:if>

				<xsl:apply-templates select="//incident:IncidentReportNDExIncidentMetadata "/>

			</xsl:element>
		</xsl:element>
	</xsl:template>

	<!--===================== Incident Arrest Template ===================== -->

	<xsl:template match="incident:IncidentArrest">

		<xsl:element name="table">
			<xsl:attribute name="class">normal narrow</xsl:attribute>
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:attribute name="class">group</xsl:attribute>
					<xsl:text>Arrest</xsl:text>
				</xsl:element>
			</xsl:element>

			<!--
			<tr>
			<th>Subject</th>
			<td>Bart Simpson</td>
			</tr>
		-->
			<xsl:element name="tr">
				<!-- extract the reference identifier from the current "Arrest" context and stash it in the variable -->
				<xsl:variable name="arrestref" select="jxdm:ArrestSubjectReference/@jxdm:ref"/>
				<!-- use the identifier to find the referenced subject node (wherever it is in the document, hence the "//*"
				construct), then get the subject's PersonName subnode -->
				<xsl:variable name="subject" select="//*[@jxdm:id=$arrestref]/jxdm:PersonName"/>
				<xsl:element name="th">
					<xsl:text>Subject</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:if test="$subject">
						<xsl:call-template name="personFullNameResolver">
							<xsl:with-param name="personNameNode" select="$subject"/>
						</xsl:call-template>
					</xsl:if>
				</xsl:element>
			</xsl:element>
			<!--
			<tr>
			<th>Arrest Type Code</th>
			<td>T</td>
			</tr>
		-->

			<xsl:variable name="arrestTypeCode" select=".//jxdm:ArrestTypeCode[not(@xsi:nil)]"/>
			<!-- display row only if value found. WATCH VARIABLE SCOPE! -->
			<xsl:if test="$arrestTypeCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Arrest Type Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$arrestTypeCode"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>
			<!--
			<tr>
			<th>Charge UCR Code</th>
			<td>240</td>
			</tr>
		-->

			<xsl:apply-templates select="jxdm:ArrestCharge"/>

			<!--
			Moved StatuteCode and StatuteText to ArrestCharge template they are related to ArrestCharge
		
			<xsl:variable name="statuteCode" select="//jxdm:StatuteOffenseCode"/>

			<xsl:if test="$statuteCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Charge Statute Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$statuteCode">
							<xsl:value-of select="$statuteCode"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
			</xsl:if>
		  <xsl:variable name="statuteText" select=".//jxdm:StatuteText"/>

			<xsl:if test="$statuteCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Charge Statute Text</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:if test="$statuteText">
							<xsl:value-of select="$statuteText"/>
						</xsl:if>
					</xsl:element>
				</xsl:element>
				</xsl:if>-->

			<xsl:variable name="arrestSubjectCountCode"
				select=".//jxdm:ArrestSubjectCountCode[normalize-space()]"/>
			<!-- display row only if value found. WATCH VARIABLE SCOPE! -->
			<xsl:if test="$arrestSubjectCountCode">
				<xsl:element name="tr">
					<xsl:element name="th">
						<xsl:text>Arrest Subject Count Code</xsl:text>
					</xsl:element>
					<xsl:element name="td">
						<xsl:value-of select="$arrestSubjectCountCode"/>
					</xsl:element>
				</xsl:element>
			</xsl:if>

			<xsl:if test=".//incident:ArrestOfficial">
				<xsl:call-template name="arrestOfficial">
					<xsl:with-param name="arrestOfficial"
						select="./incident:IncidentArrest/incident:ArrestOfficial"/>
				</xsl:call-template>

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

	<!--=================  Arrest Charge ==================-->

	<xsl:template match="jxdm:ArrestCharge">
		<xsl:variable name="ucr" select="jxdm:ChargeReporting/jxdm:ChargeUCRCode"/>
		<xsl:if test="$ucr">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Charge UCR Code</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:if test="$ucr">
						<xsl:value-of select="$ucr"/>
					</xsl:if>
				</xsl:element>
			</xsl:element>
		</xsl:if>
		
		<xsl:variable name="statuteOffenseCode" select=".//jxdm:StatuteOffenseCode"/>
		<xsl:if test="string-length($statuteOffenseCode) &gt; 0 ">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Statute Offense Code</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:value-of select="$statuteOffenseCode"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>
		<!--
			<tr>
			<th>Charge Statute Text</th>
			<td>Thou shalt not harrass the manager of a Seven-Eleven</td>
			</tr>
		-->
		
		<xsl:variable name="statuteCode" select=".//jxdm:StatuteCodeID"/>
		<xsl:if test="string-length($statuteCode) &gt; 0 ">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Charge Statute Code</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:value-of select="$statuteCode"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>
		
		<xsl:variable name="statuteText" select=".//jxdm:StatuteText"/>
		<!-- display row only if value found. WATCH VARIABLE SCOPE! -->
		<xsl:if test="string-length($statuteText) &gt; 0 ">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Charge Statute Text</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:if test="$statuteText">
						<xsl:value-of select="$statuteText"/>
					</xsl:if>
				</xsl:element>
			</xsl:element>
		</xsl:if>

	</xsl:template>

	<!--===============  Incident Response Organization================-->

	<xsl:template name="IncidentResponseOrganization">
		<xsl:param name="responseOrganization"/>
		<xsl:element name="tr">
			<xsl:element name="th">
				<xsl:attribute name="colspan">3</xsl:attribute>
				<xsl:attribute name="class">group</xsl:attribute>
				<xsl:text>Response Organization</xsl:text>
			</xsl:element>
		</xsl:element>

		<!--<xsl:variable name='OrgID' select='incident:IncidentResponseOrganization/jxdm:OrganizationORIID' />
	    <xsl:if test='$OrgID'>
		<xsl:element name='tr'>
			<xsl:element name='th'>
				<xsl:text>Organization ID</xsl:text>
			</xsl:element>
			<xsl:element name='td'>
				<xsl:attribute name='colspan'>2</xsl:attribute>
				<xsl:value-of select='$OrgID'/>
			</xsl:element>
		</xsl:element>
		</xsl:if>-->

		<xsl:variable name="orgName"
			select="$responseOrganization/jxdm:OrganizationName[normalize-space()]"/>
		<xsl:if test="$orgName">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Organization Name</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$orgName"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<xsl:variable name="orgID"
			select="$responseOrganization/jxdm:OrganizationID/jxdm:ID[normalize-space()]"/>
		<xsl:if test="$orgID">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Organization ID</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$orgID"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<xsl:variable name="organizationTypeText"
			select="$responseOrganization/jxdm:OrganizationTypeText[normalize-space()]"/>
		<xsl:if test="$organizationTypeText">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Organization Type Text</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$organizationTypeText"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<xsl:variable name="organizationAddress">
			<xsl:call-template name="streetAddressFormatter">
				<xsl:with-param name="locationAddressNode"
					select="$responseOrganization//jxdm:LocationAddress"/>
			</xsl:call-template>
		</xsl:variable>

		<xsl:if test="$organizationAddress">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Address</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$organizationAddress"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<xsl:variable name="telephoneNumberUsageDescriptionText"
			select="$responseOrganization//incident:TelephoneNumberUsageDescriptionText[normalize-space()]"/>
		<xsl:if test="$telephoneNumberUsageDescriptionText">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Telephone Number Usage Description Text</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$telephoneNumberUsageDescriptionText"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<xsl:variable name="telephoneNumber"
			select="$responseOrganization//jxdm:TelephoneNumberFullID[normalize-space()]"/>
		<xsl:if test="$telephoneNumber">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Telephone Number </xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$telephoneNumber"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

	</xsl:template>

	<!--================= Incident Response Person Role template ==================-->

	<xsl:template match="//incident:IncidentResponsePersonRole">

		<xsl:element name="tr">
			<xsl:element name="th">
				<xsl:attribute name="colspan">3</xsl:attribute>
				<xsl:attribute name="class">group</xsl:attribute>
				<xsl:text>Response Person</xsl:text>
			</xsl:element>
		</xsl:element>

		<xsl:variable name="responsePersonRoleDesc"
			select="incident:IncidentRoleDescription[normalize-space()]"/>
		<xsl:if test="$responsePersonRoleDesc">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Role</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$responsePersonRoleDesc"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<xsl:variable name="RoleIsReporterIndicator"
			select="incident:IncidentRoleIsReporterIndicator[normalize-space()]"/>
		<!-- display row only if element is  found and it's not empty  -->
		<xsl:if test="$RoleIsReporterIndicator">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text> Reporter Indicator</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:attribute name="colspan">2</xsl:attribute>
					<xsl:value-of select="$RoleIsReporterIndicator"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>

		<!--
		<tr>
		<th>Full Name</th>
		<th>Position</th>
		<th>Badge #</th>
		</tr>
	-->
		<xsl:element name="tr">
			<xsl:element name="th">
				<xsl:text>Full Name</xsl:text>
			</xsl:element>
			<xsl:element name="th">
				<xsl:text>Position</xsl:text>
			</xsl:element>
			<xsl:element name="th">
				<xsl:text>Badge #</xsl:text>
			</xsl:element>
		</xsl:element>

		<!--
		<tr>
		<td>Clancy Wiggum</td>
		<td>Police Chief</td>
		<td>12345</td>
		</tr>
	-->
		<xsl:element name="tr">
			<xsl:variable name="fullName">
				<xsl:call-template name="personFullNameResolver">
					<xsl:with-param name="personNameNode"
						select="incident:IncidentRoleEnforcementOfficial/jxdm:PersonName"/>
				</xsl:call-template>
			</xsl:variable>
			<xsl:variable name="position"
				select="incident:IncidentRoleEnforcementOfficial/jxdm:EnforcementOfficialTypeText"/>
			<xsl:variable name="badgeNum"
				select="incident:IncidentRoleEnforcementOfficial/jxdm:EnforcementOfficialBadgeID"/>
			<xsl:element name="td">
				<xsl:if test="$fullName">
					<xsl:value-of select="$fullName"/>
				</xsl:if>
			</xsl:element>
			<xsl:element name="td">
				<xsl:if test="$position">
					<xsl:value-of select="$position"/>
				</xsl:if>
			</xsl:element>
			<xsl:element name="td">
				<xsl:if test="$badgeNum">
					<xsl:value-of select="$badgeNum"/>
				</xsl:if>
			</xsl:element>
		</xsl:element>
	</xsl:template>

	<!--====================  Location Map =======================-->

	<xsl:template name="displayMap">
		<xsl:param name="address"/>
		<xsl:param name="mapID"/>
		<xsl:if test="$address != '' ">
			<xsl:variable name="formattedAddress" select="replace($address ,'&#x9;' ,' ')"/>
			<span>
				<xsl:attribute name="id">spanMapId<xsl:value-of select="$mapID"/></xsl:attribute>
				<xsl:attribute name="onkeyup">if(event.keyCode==32)
						javascript:toggleMap("iframeDivID<xsl:value-of select="$mapID"
						/>","iframeID<xsl:value-of select="$mapID"/>","spanMapId<xsl:value-of
						select="$mapID"/>", "displayMap.htm?address=<xsl:value-of
						select="$formattedAddress"/>"); </xsl:attribute>
				<xsl:attribute name="onclick">javascript:toggleMap("iframeDivID<xsl:value-of
						select="$mapID"/>","iframeID<xsl:value-of select="$mapID"
						/>","spanMapId<xsl:value-of select="$mapID"/>",
						"displayMap.htm?address=<xsl:value-of select="$formattedAddress"/>"); </xsl:attribute>
				<xsl:attribute name="onmouseover">this.style.cursor='hand';this.style.color='red';</xsl:attribute>
				<xsl:attribute name="onmouseout">this.style.color='blue';</xsl:attribute>
				<xsl:attribute name="title">Opens the Map</xsl:attribute>
				<xsl:attribute name="class">mapSpan</xsl:attribute> Map </span>
			<DIV>
				<xsl:attribute name="id">iframeDivID<xsl:value-of select="$mapID"/></xsl:attribute>
				<xsl:attribute name="class">mapDiv</xsl:attribute>
				<iframe src="static_html/loadingMap.html" width="540px" height="340px"
					scrolling="no">
					<xsl:attribute name="id">iframeID<xsl:value-of select="$mapID"/></xsl:attribute>
				</iframe>
			</DIV>
		</xsl:if>
	</xsl:template>

	<!--======================Eye color ========================-->
	<xsl:template name="PersonEyeDetails">
		<xsl:param name="eyeColorCode"/>
		<xsl:param name="eyeColorText"/>

		<xsl:if
			test="string-length($eyeColorCode) &gt; 0 or string-length($eyeColorText) &gt; 0">
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Eye Color code/text</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:value-of select="$eyeColorCode"/>
					<xsl:if
						test="string-length($eyeColorCode) &gt; 0 and string-length($eyeColorText)&gt; 0">
						<xsl:text> / </xsl:text>
					</xsl:if>
					<xsl:value-of select="$eyeColorText"/>
				</xsl:element>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<!--====================== Image ========================-->
	<xsl:template match="incident:ExtendedPersonInformation//incident:PersonDigitalImage">
		<xsl:if test="normalize-space(jxdm:BinaryObject.Base64)">
			<xsl:variable name="id" select="generate-id()"></xsl:variable>
			<xsl:variable name="containerId" select="concat('container',$id)"></xsl:variable>
			<xsl:variable name="pictureId" select="concat('picture', $id)"></xsl:variable>
			<xsl:element name="tr">
				<xsl:element name="th">
					<xsl:text>Image</xsl:text>
				</xsl:element>
				<xsl:element name="td">
					<xsl:element name="div">
						<xsl:attribute name="id"><xsl:value-of select="$containerId"></xsl:value-of></xsl:attribute>
						<xsl:attribute name="class">container</xsl:attribute>
						<xsl:element name="img">
							<xsl:attribute name="id"><xsl:value-of select="$pictureId"/></xsl:attribute>
							<xsl:attribute name="class">picture</xsl:attribute>
							<xsl:attribute name="onload">javascript:scaleSize("<xsl:value-of select="$containerId"/>", "<xsl:value-of select="$pictureId"/>");</xsl:attribute>
							<xsl:attribute name="src"
								><xsl:value-of select="jxdm:BinaryFormatTypeText"/></xsl:attribute>
						</xsl:element>
					</xsl:element>					
				</xsl:element>
			</xsl:element>
		</xsl:if>		
	</xsl:template>
</xsl:stylesheet>

