<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exchange="http://correctionscoe.org/IEPD/Exchange/OffenderTrackingRecord/1.0/" xmlns:ext="http://correctionscoe.org/IEPD/Extensions/OffenderTrackingRecordExtension/1.0/" xmlns:Vendor_D-ext="http://correctionscoe.org/IEPD/Extensions/Vendor_DOffenderTrackingRecordExtension/1.0/" xmlns:geo="http://release.niem.gov/niem/adapters/geospatial/3.0/" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:j="http://release.niem.gov/niem/domains/jxdm/5.1/" xmlns:structures="http://release.niem.gov/niem/structures/3.0/" xmlns:nc="http://release.niem.gov/niem/niem-core/3.0/">
	<xsl:output indent="yes" method="xml" omit-xml-declaration="yes"/>
	<xsl:template match="/OffenderTrackingInformation">
		<!--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-->
		<exchange:OffenderTrackingRecord>
			<xsl:apply-templates select="DocumentCreationDate"/>
			<xsl:apply-templates select="Person/PersonOtherIdentification" mode="enrolleeID"/>
			<xsl:apply-templates select="Person" mode="subject"/>
			<xsl:apply-templates select="Offendertracking/TrackingPosition"/>
			<xsl:apply-templates select="Person"/>
		</exchange:OffenderTrackingRecord>
	</xsl:template>
	<!--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-->
	<xsl:template match="Person/PersonOtherIdentification" mode="enrolleeID">
		<xsl:if test=" ./IdentificationCategoryText = 'Vendor_D Record ID'">
			<ext:TrackingAssignment>
				<ext:TrackingSupervision>
					<nc:ActivityIdentification>
						<nc:IdentificationID>
							<xsl:value-of select="./IdentificationID"/>
						</nc:IdentificationID>
						<nc:IdentificationCategoryText>Enrollee ID</nc:IdentificationCategoryText>
					</nc:ActivityIdentification>
				</ext:TrackingSupervision>
			</ext:TrackingAssignment>
		</xsl:if>
	</xsl:template>
	<xsl:template match="Offendertracking/TrackingPosition">
		<ext:OffenderTracking>
			<ext:TrackingPosition>
				<xsl:apply-templates select="PositionRecordID"/>
				<xsl:apply-templates select="TrackDate"/>
				<xsl:apply-templates select="GPSValidIndicator"/>
				<xsl:apply-templates select="GPSTrackCoordinates" mode="track"/>
				<xsl:apply-templates select="Speed"/>
				<xsl:apply-templates select="BatteryVoltage"/>
				<xsl:apply-templates select="BatteryOnChargerIndicator"/>
				<xsl:apply-templates select="ShieldingDetectedIndicator"/>
				<xsl:apply-templates select="JammingDetectedIndicator"/>
				<xsl:apply-templates select="SatellitesInViewQuantity"/>
				<xsl:apply-templates select="SatellitesUsedQuantity"/>
				<xsl:apply-templates select="HDOP"/>
				<xsl:apply-templates select="GSMSignal"/>
				<xsl:apply-templates select="CellTowerID"/>
				<xsl:apply-templates select="CellLocationValidIndicator"/>
				<xsl:apply-templates select="CellLocation" mode="track"/>
			</ext:TrackingPosition>
		</ext:OffenderTracking>
	</xsl:template>
	<xsl:template match="GSMSignal">
		<ext:GPSSignalMeasure>
			<nc:MeasureValueText>
				<xsl:value-of select="."/>
			</nc:MeasureValueText>
			<nc:MeasureUnitText>
				<xsl:value-of select="./@uom"/>
			</nc:MeasureUnitText>
		</ext:GPSSignalMeasure>
	</xsl:template>
	<xsl:template match="GPSTrackCoordinates" mode="track">
		<ext:TrackingPoint>
			<geo:LocationGeospatialPoint>
				<gml:Point>
					<xsl:attribute name="gml:id"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
					<gml:pos>
						<xsl:value-of select="."/>
					</gml:pos>
				</gml:Point>
			</geo:LocationGeospatialPoint>
			<xsl:apply-templates select="../TrackDate/@uom"/>
		</ext:TrackingPoint>
	</xsl:template>
	<xsl:template match="Person">
		<nc:Person>
			<xsl:attribute name="structures:id"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
			<xsl:apply-templates select="PersonBirthdate"/>
			<xsl:apply-templates select="PersonEyeColorText"/>
			<xsl:apply-templates select="PersonHairColorText"/>
			<xsl:apply-templates select="PersonHeight"/>
			<xsl:apply-templates select="PersonName"/>
			<xsl:apply-templates select="PersonRaceText"/>
			<xsl:apply-templates select="PersonSexText"/>
			<xsl:apply-templates select="PersonWeight"/>
			<xsl:apply-templates select="PersonOtherIdentification" mode="personid"/>
		</nc:Person>
	</xsl:template>
	<xsl:template match="PersonBirthdate">
		<nc:PersonBirthDate>
			<xsl:call-template name="date"/>
		</nc:PersonBirthDate>
	</xsl:template>
	<xsl:template match="PersonEyeColorText">
		<nc:PersonEyeColorText>
			<xsl:value-of select="."/>
		</nc:PersonEyeColorText>
	</xsl:template>
	<xsl:template match="PersonHairColorText">
		<nc:PersonHairColorText>
			<xsl:value-of select="."/>
		</nc:PersonHairColorText>
	</xsl:template>
	<xsl:template match="PersonHeight">
		<nc:PersonHeightMeasure>
			<nc:MeasureValueText>
				<xsl:value-of select="."/>
			</nc:MeasureValueText>
			<nc:MeasureUnitText>
				<xsl:value-of select="./@uom"/>
			</nc:MeasureUnitText>
		</nc:PersonHeightMeasure>
	</xsl:template>
	<xsl:template match="PersonWeight">
		<nc:PersonWeightMeasure>
			<nc:MeasureValueText>
				<xsl:value-of select="."/>
			</nc:MeasureValueText>
			<nc:MeasureUnitText>
				<xsl:value-of select="./@uom"/>
			</nc:MeasureUnitText>
		</nc:PersonWeightMeasure>
	</xsl:template>
	<xsl:template match="PersonName">
		<nc:PersonName>
			<xsl:apply-templates select="PersonGivenName"/>
			<xsl:apply-templates select="PersonSurName"/>
		</nc:PersonName>
	</xsl:template>
	<xsl:template match="PersonGivenName">
		<nc:PersonGivenName>
			<xsl:value-of select="."/>
		</nc:PersonGivenName>
	</xsl:template>
	<xsl:template match="PersonSurName">
		<nc:PersonSurName>
			<xsl:value-of select="."/>
		</nc:PersonSurName>
	</xsl:template>
	<xsl:template match="PersonRaceText">
		<nc:PersonRaceText>
			<xsl:value-of select="."/>
		</nc:PersonRaceText>
	</xsl:template>
	<xsl:template match="PersonSexText">
		<nc:PersonSexText>
			<xsl:value-of select="."/>
		</nc:PersonSexText>
	</xsl:template>
	<xsl:template match="PersonOtherIdentification" mode="personid">
		<xsl:variable name="idcategory" select="IdentificationCategoryText"/>
		<xsl:if test=" $idcategory = 'Vendor_D Primary ID'">
			<Vendor_D-ext:PersonPrimaryIdentification>
				<nc:IdentificationID>
					<xsl:value-of select="IdentificationID"/>
				</nc:IdentificationID>
				<nc:IdentificationCategoryText>
					<xsl:value-of select="IdentificationCategoryText"/>
				</nc:IdentificationCategoryText>
			</Vendor_D-ext:PersonPrimaryIdentification>
		</xsl:if>
		<xsl:if test=" $idcategory = 'Vendor_D Secondary ID'">
			<Vendor_D-ext:PersonSecondaryIdentification>
				<nc:IdentificationID>
					<xsl:value-of select="IdentificationID"/>
				</nc:IdentificationID>
				<nc:IdentificationCategoryText>
					<xsl:value-of select="IdentificationCategoryText"/>
				</nc:IdentificationCategoryText>
			</Vendor_D-ext:PersonSecondaryIdentification>
		</xsl:if>
	</xsl:template>
	<xsl:template match="TrackDate/@uom">
		<ext:TrackingCategoryText>
			<xsl:value-of select="."/>
		</ext:TrackingCategoryText>
	</xsl:template>
	<xsl:template match="CellLocationCoordinates/@crs">
		<ext:TrackingCategoryText>
			<xsl:value-of select="."/>
		</ext:TrackingCategoryText>
	</xsl:template>
	<xsl:template match="Speed">
		<nc:SpeedMeasure>
			<nc:MeasureValueText>
				<xsl:value-of select="."/>
			</nc:MeasureValueText>
			<nc:MeasureUnitText>
				<xsl:value-of select="./@uom"/>
			</nc:MeasureUnitText>
		</nc:SpeedMeasure>
	</xsl:template>
	<xsl:template match="BatteryVoltage">
		<ext:BatteryLevelMeasure>
			<nc:MeasureValueText>
				<xsl:value-of select="."/>
			</nc:MeasureValueText>
			<nc:MeasureUnitText>
				<xsl:value-of select="./@uom"/>
			</nc:MeasureUnitText>
		</ext:BatteryLevelMeasure>
	</xsl:template>
	<xsl:template match="BatteryOnChargerIndicator">
		<ext:BatteryOnChargerIndicator>
			<xsl:value-of select="."/>
		</ext:BatteryOnChargerIndicator>
	</xsl:template>
	<xsl:template match="ShieldingDetectedIndicator">
		<ext:ShieldingDetectedIndicator>
			<xsl:value-of select="."/>
		</ext:ShieldingDetectedIndicator>
	</xsl:template>
	<xsl:template match="JammingDetectedIndicator">
		<ext:JammingDetectedIndicator>
			<xsl:value-of select="."/>
		</ext:JammingDetectedIndicator>
	</xsl:template>
	<xsl:template match="SatellitesInViewQuantity">
		<ext:SatellitesInViewQuantity>
			<xsl:value-of select="."/>
		</ext:SatellitesInViewQuantity>
	</xsl:template>
	<xsl:template match="SatellitesUsedQuantity">
		<ext:SatellitesUsedQuantity>
			<xsl:value-of select="."/>
		</ext:SatellitesUsedQuantity>
	</xsl:template>
	<xsl:template match="DocumentCreationDate">
		<nc:DocumentCreationDate>
			<xsl:call-template name="date-time"/>
		</nc:DocumentCreationDate>
	</xsl:template>
	<xsl:template match="HDOP">
		<ext:HDOPMeasure>
			<nc:MeasureValueText>
				<xsl:value-of select="."/>
			</nc:MeasureValueText>
		</ext:HDOPMeasure>
	</xsl:template>
	<xsl:template match="CellTowerID">
		<ext:CellTowerID>
			<nc:IdentificationID>
				<xsl:value-of select="."/>
			</nc:IdentificationID>
			<nc:IdentificationCategoryText>
				<xsl:value-of select="./@system"/>
			</nc:IdentificationCategoryText>
		</ext:CellTowerID>
	</xsl:template>
	<xsl:template match="CellLocationValidIndicator">
		<ext:CellTrackValidIndicator>
			<xsl:value-of select="."/>
		</ext:CellTrackValidIndicator>
	</xsl:template>
	<xsl:template match="CellLocation" mode="track">
		<ext:CellTrackingPoint>
			<xsl:apply-templates select="CellLocationCoordinates"/>
			<xsl:apply-templates select="CellLocationSource"/>
			<xsl:apply-templates select="./@crs"/>
		</ext:CellTrackingPoint>
	</xsl:template>
	<xsl:template match="CellLocationCoordinates">
		<geo:LocationGeospatialPoint>
			<gml:Point>
				<xsl:attribute name="gml:id"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
				<gml:pos>
					<xsl:value-of select="."/>
				</gml:pos>
			</gml:Point>
		</geo:LocationGeospatialPoint>
	</xsl:template>
	<xsl:template match="Person" mode="subject">
		<j:Subject>
			<nc:RoleOfPerson>
				<xsl:attribute name="structures:ref"><xsl:value-of select="generate-id(.)"/></xsl:attribute>
			</nc:RoleOfPerson>
		</j:Subject>
	</xsl:template>
	<xsl:template match="PositionRecordID">
		<ext:PositionRecordID>
			<xsl:value-of select="."/>
		</ext:PositionRecordID>
	</xsl:template>
	<xsl:template match="TrackDate">
		<ext:TrackDateTimeLocal>
			<xsl:call-template name="date-time"/>
		</ext:TrackDateTimeLocal>
	</xsl:template>
	<xsl:template match="GPSValidIndicator">
		<ext:GPSValidIndicator>
			<xsl:value-of select="."/>
		</ext:GPSValidIndicator>
	</xsl:template>
	<xsl:template match="CellLocationSource">
		<ext:TrackingSourceText>
			<xsl:value-of select="."/>
		</ext:TrackingSourceText>
	</xsl:template>
	<xsl:template name="date">
		<nc:Date>
			<xsl:value-of select="."/>
		</nc:Date>
	</xsl:template>
	<xsl:template name="date-time">
		<nc:DateTime>
			<xsl:value-of select="."/>
		</nc:DateTime>
	</xsl:template>
</xsl:stylesheet>
