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

<!-- 
FDT: device identification transformation for VVO 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:vvoident="x-schema:FDTVVOIdentSchema.xml"
		xmlns:vvodevice="x-schema:FDTVVODeviceTypeIdentSchema.xml"
		xmlns:vvoscan="x-schema:FDTVVOScanIdentSchema.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.23"/>
	</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="//vvoscan:ScanIdentifications"/>
			<xsl:apply-templates select="//vvodevice:DeviceIdentifications"/>
	</xsl:template>
<!-- 
VVO identification list
-->
	<xsl:template match="vvodevice: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="vvodevice:DeviceIdentification"/>
				</xsl:element>
		<xsl:text disable-output-escaping="yes">&lt;/FDT&gt;</xsl:text>
	</xsl:template>
<!-- 
VVO catalog identifcation
-->
	<xsl:template match="vvodevice:DeviceIdentification">
			<xsl:element name="DeviceIdentification">
				<xsl:attribute name="ident:idDTMSupportLevel">
					<xsl:value-of select="@vvoident:idDTMSupportLevel"/>
				</xsl:attribute>
				<xsl:apply-templates select="vvodevice:IdBusProtocol"/>
				<xsl:element name="IdBusProtocolVersion">
					<xsl:attribute name="ident:value">1</xsl:attribute>
					<xsl:attribute name="ident:protocolSpecificName">VVO Revision</xsl:attribute>
				</xsl:element>
				<xsl:element name="IdSoftwareRevision">
					<xsl:attribute name="ident:value">1</xsl:attribute>
					<xsl:attribute name="ident:protocolSpecificName">Software Revision</xsl:attribute>
				</xsl:element>
				<xsl:element name="IdHardwareRevision">
					<xsl:attribute name="ident:value">1</xsl:attribute>
					<xsl:attribute name="ident:protocolSpecificName">Hardware Revision</xsl:attribute>
				</xsl:element>
		
				<xsl:apply-templates select="vvodevice:IdManufacturer"/>
				<xsl:apply-templates select="vvodevice:IdDtmTypeID"/>
			</xsl:element>
	</xsl:template>
<!-- 
VVO scan list
-->
	<xsl:template match="vvoscan: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="vvoscan:ScanIdentification"/>
				</xsl:element>
		<xsl:text disable-output-escaping="yes">&lt;/FDT&gt;</xsl:text>
	</xsl:template>


<!-- 
VVO scan identifcation
-->
	<xsl:template match="vvoscan:ScanIdentification">
			<xsl:element name="ScanIdentification">
				<xsl:apply-templates select="@configuredState" />
				<xsl:apply-templates select="fdt:CommunicationError"/>
				<xsl:apply-templates select="vvoscan:IdBusProtocol"/>

				<xsl:element name="IdBusProtocolVersion">
					<xsl:attribute name="ident:value">1</xsl:attribute>
					<xsl:attribute name="ident:protocolSpecificName">VVO Revision</xsl:attribute>
				</xsl:element>
				<xsl:element name="IdSoftwareRevision">
					<xsl:attribute name="ident:value">1</xsl:attribute>
					<xsl:attribute name="ident:protocolSpecificName">Software Revision</xsl:attribute>
				</xsl:element>
				<xsl:element name="IdHardwareRevision">
					<xsl:attribute name="ident:value">1</xsl:attribute>
					<xsl:attribute name="ident:protocolSpecificName">Hardware Revision</xsl:attribute>
				</xsl:element>

				<xsl:apply-templates select="vvoscan:IdManufacturer"/>
				<xsl:apply-templates select="vvoscan:IdDtmTypeID"/>
				<xsl:apply-templates select="vvoscan:IdTag"/>
				<xsl:apply-templates select="vvoscan:IdAddress"/>
			</xsl:element>
	</xsl:template>
<!-- 
configured attribute
-->
	<xsl:template match="@configuredState">
		<xsl:attribute name="configuredState">
			<xsl:value-of select="."/>
		</xsl:attribute>
	</xsl:template>

<!-- 
vvoscanIdentification: device tag, just copy
-->
	<xsl:template match="vvoscan:IdTag">
		<xsl:element name="IdDeviceTag">
			<xsl:attribute name="ident:value"><xsl:value-of select="@vvoident:tag"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Tag</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
vvoscanIdentification: 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>
<!-- 
vvoscanIdentification: serialnumber
-->
	<xsl:template match="vvoscan:IdSerialNumber">
		<xsl:element name="IdSerialNumber">
			<xsl:attribute name="ident:value"><xsl:value-of select="@vvoident:deviceID"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Device Identification Number</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
vvoscanIdentification: busaddress, just copy
-->
	<xsl:template match="vvoscan:IdAddress">
		<xsl:element name="IdAddress">
			<xsl:attribute name="ident:value"><xsl:value-of select="@vvoident:address"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Polling Address</xsl:attribute>
		</xsl:element>
	</xsl:template>

<!-- 
VVO Manufacaturer
-->
	<xsl:template match="vvodevice:IdManufacturer">
		<xsl:param name="manid" select="@vvoident: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="vvoscan:IdManufacturer">
		<xsl:element name="IdManufacturer">
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@vvoident:manufacturerIdentificationCode"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Manufacturer Identification Code</xsl:attribute>
		</xsl:element>
	</xsl:template>
<!-- 
DevId:IdBusProtocol
-->
	<xsl:template match="vvodevice:IdBusProtocol">
		<xsl:param name="manid" select="@vvoident: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">VVO</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="vvoscan:IdBusProtocol">
		<xsl:element name="IdBusProtocol">
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@vvoident:busProtocol"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">VVO</xsl:attribute>
		</xsl:element>
	</xsl:template>
	
<!-- 
DevId:IdBusProtocolVersion
-->
	<xsl:template match="vvodevice:IdBusProtocolVersion">
		<xsl:element name="IdBusProtocolVersion">
			<xsl:attribute name="ident:value">1</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">VVO Revision</xsl:attribute>
		</xsl:element>
	</xsl:template>
	<xsl:template match="vvoscan:IdBusProtocolVersion">
		<xsl:element name="IdBusProtocolVersion">
			<xsl:attribute name="ident:value">1</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">VVO Revision</xsl:attribute>
		</xsl:element>
	</xsl:template>
	
<!-- 
VVO device type
-->
	<xsl:template match="vvodevice:IdDtmTypeID">
		<xsl:param name="value" select="@vvoident:dtmTypeID"/>
		<xsl:element name="IdTypeID">
			<xsl:attribute name="ident:protocolSpecificName">Device Type Code</xsl:attribute>
			<xsl:call-template name="genMatch">
				<xsl:with-param name="value" select="$value"/>
			</xsl:call-template>
		</xsl:element>
	</xsl:template>
	<xsl:template match="vvoscan:IdDtmTypeID">
		<xsl:element name="IdTypeID">
			<xsl:attribute name="ident:value">
				<xsl:value-of select="@vvoident:dtmTypeID"/>
			</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Device Type Code</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="vvoident:RegExpr"/>
	</xsl:template>
<!-- 
generate regular exressions
-->
	<xsl:template match="vvoident: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>