<?xml version="1.0" encoding="UTF-8"?>

<!-- 
FDT: device identification transformation for Simulation device identification xml files
-->
<xsl:transform 	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
		xmlns:str="http://xsltsl.org/string" 
		xmlns:ident="x-schema:DTMIdentSchema.xml"
		xmlns:fdt="x-schema:FDTDataTypesSchema.xml"
		xmlns:scanident="x-schema:DTMScanIdentSchema.xml"
		xmlns:devident="x-schema:DTMDeviceTypeIdentSchema.xml"
		xmlns:simulationident="x-schema:FDTSimulationIdentSchema.xml"
		xmlns:simulationdevice="x-schema:FDTSimulationDeviceTypeIdentSchema.xml"
		xmlns:simulationscan="x-schema:FDTSimulationScanIdentSchema.xml" version="2.0">
	<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
		<!-- 
FDT: version of this file
	-->

	<xsl:variable name="FileVersion">
		<xsl:number value="1.21"/>
	</xsl:variable>
	<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<!-- 
root: transform device or scan identification
-->
	<xsl:template match="/">
			<xsl:apply-templates select="//simulationscan:ScanIdentifications"/>
			<xsl:apply-templates select="//simulationdevice:DeviceIdentifications"/>
	</xsl:template>
<!-- 
Simulation identification list
-->
	<xsl:template match="simulationdevice:DeviceIdentifications">
		<xsl:text disable-output-escaping="yes">&lt;?xml version="1.0"?&gt;
	&lt;!-- This file is created by FDTxxxIdentTransformation.xsl after transformation of xxxDTMDeviceIdentificationInstance.xml --&gt;
	&lt;FDT xmlns="x-schema:DTMDeviceTypeIdentSchema.xml" 
	 xmlns:ident="x-schema:DTMIdentSchema.xml" xmlns:fdt="x-schema:FDTDataTypesSchema.xml" &gt;</xsl:text>
				<xsl:element name="DeviceIdentifications">
					<xsl:apply-templates select="simulationdevice:DeviceIdentification"/>
				</xsl:element>
		<xsl:text disable-output-escaping="yes">&lt;/FDT&gt;</xsl:text>
	</xsl:template>
<!-- 
Simulation catalog identifcation
-->
	<xsl:template match="simulationdevice:DeviceIdentification">
			<xsl:element name="DeviceIdentification">
				<xsl:attribute name="ident:idDTMSupportLevel">
					<xsl:value-of select="@simulationident:idDTMSupportLevel"/>
				</xsl:attribute>
				<xsl:apply-templates select="simulationdevice:IdBusProtocol"/>
				<xsl:apply-templates select="simulationdevice:IdBusProtocolVersion"/>
				<xsl:apply-templates select="simulationdevice:IdManufacturer"/>
				<xsl:apply-templates select="simulationdevice:IdTypeID"/>
				<xsl:apply-templates select="simulationdevice:IdSoftwareRevision"/>
				<xsl:apply-templates select="simulationdevice:IdHardwareRevision"/>
				<xsl:element name="IdValues">
					<xsl:apply-templates select="simulationdevice:DeviceCommandRevisionLevel"/>
					<xsl:apply-templates select="simulationdevice:DeviceFlag"/>
					<xsl:apply-templates select="simulationdevice:ManufacturerSpecificExtension"/>
				</xsl:element>
			</xsl:element>
	</xsl:template>
<!-- 
Simulation scan list
-->
	<xsl:template match="simulationscan:ScanIdentifications">
			<xsl:text disable-output-escaping="yes">&lt;?xml version="1.0"?&gt;
	&lt;!-- This file is created by FDTxxxIdentTransformation.xsl after transformation of xxxDTMScanIdentificationInstance.xml --&gt;&lt;FDT xmlns="x-schema:DTMScanIdentSchema.xml" 
	 xmlns:ident="x-schema:DTMIdentSchema.xml" xmlns:fdt="x-schema:FDTDataTypesSchema.xml" &gt;</xsl:text>
				<xsl:element name="ScanIdentifications">
					<xsl:attribute name="fdt:busCategory">
						<xsl:value-of select="@fdt:busCategory"/>
					</xsl:attribute>
					<xsl:attribute name="resultState">
						<xsl:value-of select="@resultState"/>
					</xsl:attribute>
					<xsl:apply-templates select="simulationscan:ScanIdentification"/>
				</xsl:element>
		<xsl:text disable-output-escaping="yes">&lt;/FDT&gt;</xsl:text>
	</xsl:template>


<!-- 
Simulation scan identifcation
-->
	<xsl:template match="simulationscan:ScanIdentification">
			<xsl:element name="ScanIdentification">
				<xsl:apply-templates select="@configuredState" />
				<xsl:apply-templates select="fdt:CommunicationError"/>
				<xsl:apply-templates select="simulationscan:IdBusProtocol"/>
				<xsl:apply-templates select="simulationscan:IdBusProtocolVersion"/>
				<xsl:apply-templates select="simulationscan:IdAddress"/>			
				<xsl:apply-templates select="simulationscan:IdManufacturer"/>
				<xsl:apply-templates select="simulationscan:IdTypeID"/>
				<xsl:apply-templates select="simulationscan:IdSoftwareRevision"/>
				<xsl:apply-templates select="simulationscan:IdHardwareRevision"/>
				<xsl:apply-templates select="simulationscan:IdTag"/>
				<xsl:apply-templates select="simulationscan:IdSerialNumber"/>
				<xsl:element name="IdValues">
					<xsl:apply-templates select="simulationscan:DeviceCommandRevisionLevel"/>
					<xsl:apply-templates select="simulationscan:DeviceFlag"/>
					<xsl:apply-templates select="simulationscan:ManufacturerSpecificExtension"/>
				</xsl:element>
			</xsl:element>
	</xsl:template>
<!-- 
configured attribute
-->
	<xsl:template match="@configuredState">
		<xsl:attribute name="configuredState">
			<xsl:value-of select="."/>
		</xsl:attribute>
	</xsl:template>

<!-- 
HartScanIdentification: device tag, just copy
-->
	<xsl:template match="simulationscan:IdTag">
		<xsl:element name="IdDeviceTag">
			<xsl:attribute name="ident:value"><xsl:value-of select="@simulationident:tag"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Tag</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
HartScanIdentification: communicationError
-->
	<xsl:template match="fdt:CommunicationError">
		<xsl:element name="fdt:CommunicationError">
			<xsl:attribute name="communicationError"><xsl:value-of select="@communicationError"/></xsl:attribute>
			<xsl:attribute name="tag"><xsl:value-of select="@tag"/></xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
HartScanIdentification: serialnumber
-->
	<xsl:template match="simulationscan:IdSerialNumber">
		<xsl:element name="IdSerialNumber">
			<xsl:attribute name="ident:value"><xsl:value-of select="@simulationident:deviceID"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Device Identification Number</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
HartScanIdentification: busaddress, just copy
-->
	<xsl:template match="simulationscan:IdAddress">
		<xsl:element name="IdAddress">
			<xsl:attribute name="ident:value"><xsl:value-of select="@simulationident:shortAddress"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Polling Address</xsl:attribute>
		</xsl:element>
	</xsl:template>

<!-- 
HartScanIdentification: CommandRevision, saved as protocol specific value
-->
	<xsl:template match="simulationdevice:DeviceCommandRevisionLevel">
		<xsl:param name="value" select="@simulationident:deviceCommandRevisionLevel"/>
		<xsl:element name="IdValue">
			<xsl:attribute name="ident:name">DeviceCommandRevisionLevel</xsl:attribute>
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">Device Revision Level</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:DeviceCommandRevisionLevel">
		<xsl:element name="IdValue">
			<xsl:attribute name="ident:name">DeviceCommandRevisionLevel</xsl:attribute>
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@simulationident:deviceCommandRevisionLevel"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Device Revision Level</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
HartScanIdentification: DeviceFlag, saved as protocol specific value
-->
	<xsl:template match="simulationdevice:DeviceFlag">
		<xsl:param name="value" select="@simulationident:deviceFlag"/>
		<xsl:element name="IdValue">
			<xsl:attribute name="ident:name">DeviceFlag</xsl:attribute>
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">Flags</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:DeviceFlag">
		<xsl:element name="IdValue">
			<xsl:attribute name="ident:name">DeviceFlag</xsl:attribute>
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@simulationident:deviceFlag"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Flags</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
Hart Manufacaturer
-->
	<xsl:template match="simulationdevice:IdManufacturer">
		<xsl:param name="manid" select="@simulationident:manufacturerIdentificationCode"/>
		<xsl:element name="IdManufacturer">
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$manid"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">Manufacturer Identification Code</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:IdManufacturer">
		<xsl:element name="IdManufacturer">
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@simulationident:manufacturerIdentificationCode"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Manufacturer Identification Code</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
DevId:IdBusProtocol
-->
	<xsl:template match="simulationdevice:IdBusProtocol">
		<xsl:param name="manid" select="@simulationident:busProtocol"/>
		<xsl:element name="IdBusProtocol">
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$manid"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">Proprietary Stuff</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:IdBusProtocol">
		<xsl:element name="IdBusProtocol">
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@simulationident:busProtocol"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Proprietary Stuff</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
DevId:IdBusProtocolVersion
-->
	<xsl:template match="simulationdevice:IdBusProtocolVersion">
		<xsl:param name="manid" select="@simulationident:universalCommandRevisionLevel"/>
		<xsl:element name="IdBusProtocolVersion">
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$manid"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">Simulation Revision</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:IdBusProtocolVersion">
		<xsl:element name="IdBusProtocolVersion">
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@simulationident:universalCommandRevisionLevel"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Simulation Revision</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
Simulation device type
-->
	<xsl:template match="simulationdevice:IdTypeID">
		<xsl:param name="value" select="@simulationident:deviceTypeID"/>
		<xsl:element name="IdTypeID">
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">Device Type Code</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:IdTypeID">
		<xsl:element name="IdTypeID">
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@simulationident:deviceTypeID"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Device Type Code</xsl:attribute>
		</xsl:element>
	</xsl:template>

<!-- 
Simulation software revision
-->
	<xsl:template match="simulationdevice:IdSoftwareRevision">
		<xsl:param name="value" select="@simulationident:softwareRevision"/>
		<xsl:element name="IdSoftwareRevision">
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">Software Revision</xsl:attribute>
		</xsl:element>
	</xsl:template>
		<xsl:template match="simulationscan:IdSoftwareRevision">
		<xsl:param name="value" select="@simulationident:softwareRevision"/>
		<xsl:element name="IdSoftwareRevision">
			<xsl:attribute name="ident:protocolSpecificName">Software Revision</xsl:attribute>
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
		</xsl:element>
	</xsl:template>

<!-- 
Simulation hardware revision
--> 
	<xsl:template match="simulationdevice:IdHardwareRevision">
		<xsl:param name="value" select="@simulationident:hardwareRevision"/>
		<xsl:element name="IdHardwareRevision">
			<xsl:attribute name="ident:protocolSpecificName">Hardware Revision</xsl:attribute>
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:IdHardwareRevision">
		<xsl:param name="value" select="@simulationident:hardwareRevision"/>
		<xsl:element name="IdHardwareRevision">
			<xsl:attribute name="ident:protocolSpecificName">Hardware Revision</xsl:attribute>
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
		</xsl:element>
	</xsl:template>

<!-- 
ManufacturerSpecificExtension
--> 
	<xsl:template match="simulationdevice:ManufacturerSpecificExtension">
		<xsl:param name="value" select="@simulationident:manufacturerSpecificExtension"/>
		<xsl:element name="IdValue">
			<xsl:attribute name="ident:name">ManufacturerSpecificExtension</xsl:attribute>
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
			<xsl:attribute name="ident:protocolSpecificName">ManufacturerSpecificExtension</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="simulationscan:ManufacturerSpecificExtension">
		<xsl:element name="IdValue">
			<xsl:attribute name="ident:name">ManufacturerSpecificExtension</xsl:attribute>
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@simulationident:manufacturerSpecificExtension"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">ManufacturerSpecificExtension</xsl:attribute>
		</xsl:element>
	</xsl:template>


<!-- 
generate matching information
-->
	<xsl:template name="genMatch">
		<xsl:param name="value"/>
		<xsl:param name="empty"/>
		<xsl:if test="$value!=$empty">
			<xsl:attribute name="ident:value"><xsl:value-of select="$value"/></xsl:attribute>
		</xsl:if>
		<xsl:apply-templates select="simulationident:RegExpr"/>
	</xsl:template>
<!-- 
generate regular exressions
-->
	<xsl:template match="simulationident:RegExpr">
		<!-- copy pattern info -->
		<xsl:call-template name="genPattern">
			<xsl:with-param name="match" select="@match"/>
			<xsl:with-param name="nomatch" select="@nomatch"/>
		</xsl:call-template>
	</xsl:template>
<!-- 
generate pattern information
-->
	<xsl:template name="genPattern">
		<xsl:param name="match"/>
		<xsl:param name="nomatch"/>
		<xsl:param name="empty"/>
		<xsl:choose>
		<xsl:when test="$match!=$empty">
			<xsl:element name="ident:RegExpr">
				<xsl:attribute name="match"><xsl:value-of select="$match"/></xsl:attribute>
				<xsl:if test="$nomatch!=$empty">
					<xsl:attribute name="nomatch"><xsl:value-of select="$nomatch"/></xsl:attribute>
				</xsl:if>
			</xsl:element>
		</xsl:when>
		<xsl:when test="$nomatch!=$empty">
			<xsl:element name="ident:RegExpr">
				<xsl:attribute name="nomatch"><xsl:value-of select="$nomatch"/></xsl:attribute>
				<xsl:if test="$match!=$empty">
					<xsl:attribute name="match"><xsl:value-of select="$match"/></xsl:attribute>
				</xsl:if>
			</xsl:element>
		</xsl:when>
		</xsl:choose>
	</xsl:template>
</xsl:transform>