﻿<?xml version="1.0"?>
<xsl:transform	
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:ident="x-schema:DTMIdentSchema.xml"
		xmlns:fdt="x-schema:FDTDataTypesSchema.xml"
		xmlns:topology="x-schema:DTMTopologyScanSchema.xml"
		xmlns:fftypes="x-schema:FdtFFDataTypesSchema.xml"
		xmlns:fieldscan="x-schema:DtmFFSchema.xml" version="2.0">
		<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>

	
	<xsl:template match="/">
 		<xsl:apply-templates select="//topology:TopologyScan"/>
 	</xsl:template>
 	
 	
 	<xsl:template match="topology:TopologyScan">
 	<xsl:text disable-output-escaping="yes">&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="resultState">final</xsl:attribute>
				
				<xsl:if test="//topology:TopologyScan/fieldscan:FoundationFieldbusHSEDevice">
					<xsl:attribute name="fdt:busCategory">036D1692-387B-11D4-86E1-00E0987270B9</xsl:attribute>
				</xsl:if>
				
				<xsl:if test="//topology:TopologyScan/fieldscan:FoundationFieldbusH1Device">
					<xsl:attribute name="fdt:busCategory">036D1691-387B-11D4-86E1-00E0987270B9</xsl:attribute>
				</xsl:if>
				
				<xsl:apply-templates select="fieldscan:FoundationFieldbusHSEDevice"/>
				
				<xsl:apply-templates select="fieldscan:FoundationFieldbusH1Device"/>
				
						
				</xsl:element>
		<xsl:text disable-output-escaping="yes">&lt;/FDT&gt;</xsl:text>
	</xsl:template>
	
	<xsl:template match ="fieldscan:FoundationFieldbusHSEDevice">
 		
 		<xsl:element name="ScanIdentification">
 			
 		
 		<xsl:element name="IdDeviceTag">
			<xsl:attribute name="ident:value"><xsl:value-of select="@fdt:tag"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Tag</xsl:attribute>
		</xsl:element>
		
		<xsl:element name="IdSerialNumber">
			<xsl:attribute name="ident:value"><xsl:value-of select="@fftypes:devID"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Device ID</xsl:attribute>
		</xsl:element>
		
		<xsl:element name="IdSoftwareRevision">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:VfdIdentification/@ddRevision"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">DD Revision</xsl:attribute>
		</xsl:element>
			
		<xsl:element name="IdTypeID">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:VfdIdentification/@devType"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">devType</xsl:attribute>
		</xsl:element>
		
		<xsl:element name="IdManufacturer">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:VfdIdentification/@fdt:manufacturerId"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Manufacturer</xsl:attribute>
		</xsl:element>
			
		<xsl:element name="IdAddress">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:DataLinkAddress/@linkId + @nodeId + @selector"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">BusProtocol</xsl:attribute>
		</xsl:element>
			
		<xsl:element name="IdBusProtocol">
			<xsl:attribute name="ident:value">protocol_HSE</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">BusProtocol</xsl:attribute>
		</xsl:element>
 		
 			
 		</xsl:element>
 		
 	</xsl:template>
 	
 	<xsl:template match ="fieldscan:FoundationFieldbusH1Device">
 		
 		<xsl:element name="ScanIdentification">
 			
 		
 		<xsl:element name="IdDeviceTag">
			<xsl:attribute name="ident:value"><xsl:value-of select="@fdt:tag"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Tag</xsl:attribute>
		</xsl:element>
		
		<xsl:element name="IdSerialNumber">
			<xsl:attribute name="ident:value"><xsl:value-of select="@fftypes:devID"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Device ID</xsl:attribute>
		</xsl:element>
		
		<xsl:element name="IdSoftwareRevision">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:VfdIdentification/@ddRevision"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">DD Revision</xsl:attribute>
		</xsl:element>
			
		<xsl:element name="IdTypeID">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:VfdIdentification/@devType"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">devType</xsl:attribute>
		</xsl:element>
		
		<xsl:element name="IdManufacturer">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:VfdIdentification/@fdt:manufacturerId"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">Manufacturer</xsl:attribute>
		</xsl:element>
			
		<xsl:element name="IdAddress">
			<xsl:attribute name="ident:value"><xsl:value-of select="fftypes:DataLinkAddress/@linkId + @nodeId + @selector"/></xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">BusProtocol</xsl:attribute>
		</xsl:element>
			
		<xsl:element name="IdBusProtocol">
			<xsl:attribute name="ident:value">protocol_H1</xsl:attribute>
			<xsl:attribute name="ident:protocolSpecificName">BusProtocol</xsl:attribute>
		</xsl:element>
 		
 			
 		</xsl:element>
 		
 	</xsl:template>


</xsl:transform>