<?xml version="1.0" encoding="UTF-16"?>
<!--
**********************************************************************************
Overview: This XSLT searches and transforms specific elements in the source XML 
		  to target XML for both inbound and outbound interfaces. 
		  The types of transformation are as follows : 
		  1) LOV Transformation
		  2) Date Transformation

Author 	: Michael Kwee
Date 	: 2 Jan 2007

 
**********************************************************************************
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:b="urn:OEXML:r1" 
xmlns:a="http://www.siebel.com/xml/OE%20EAI%20Obtain%20Standing%20Data" 
xmlns:func="http://exslt.org/functions"
xmlns:Ext="Ext"> 
<xsl:variable name="Message_Id" select="//@MessageId"/>
<xsl:variable name="Doc_Path" select="//@EAIFS"/>
<xsl:output method="xml" encoding="UTF-16"/>
<!--
********************************************************************
Identify Interface Direction
********************************************************************
-->
<xsl:variable name="Interface_Direction">
	<xsl:choose>
		<xsl:when test="contains($Message_Id,'-Req')">
		 	<xsl:value-of select="'Siebel Outbound'"/>
		</xsl:when>
		<xsl:when test="contains($Message_Id,'-Resp')">
			<xsl:value-of select="'Siebel Inbound'"/>
		</xsl:when>
	</xsl:choose>
</xsl:variable>
	<xsl:template match="*">
		<xsl:copy>
		<xsl:choose>
			<xsl:when test="starts-with(name(),'SiebelMessage')">
				<xsl:attribute name="EAIFS"><xsl:value-of select="@EAIFS"/></xsl:attribute>
				<xsl:attribute name="T2DDuration"><xsl:value-of select="@T2DDuration"/></xsl:attribute>
				<xsl:attribute name="SubmittedBy"><xsl:value-of select="@SubmittedBy"/></xsl:attribute>
				<xsl:attribute name="MessageId"><xsl:value-of select="@MessageId"/></xsl:attribute>
				<xsl:attribute name="Timestamp">
					<xsl:call-template name="Ext:transform_datetime">
						<xsl:with-param name="Node"><xsl:value-of select="@Timestamp"/></xsl:with-param>
						<xsl:with-param name="Interface_Direction" select="$Interface_Direction"></xsl:with-param>
					</xsl:call-template>
				</xsl:attribute>
				<xsl:attribute name="T2DUnit"><xsl:value-of select="@T2DUnit"/></xsl:attribute>
				<xsl:attribute name="MessageType"><xsl:value-of select="@MessageType"/></xsl:attribute>
				<xsl:attribute name="IntObjectName"><xsl:value-of select="@IntObjectName"/></xsl:attribute>
				<xsl:attribute name="IntObjectFormat"><xsl:value-of select="@IntObjectFormat"/></xsl:attribute>
				<xsl:attribute name="ResponseURL"><xsl:value-of select="@ResponseURL"/></xsl:attribute>
				<xsl:attribute name="TransactionId"><xsl:value-of select="@TransactionId"/></xsl:attribute>
				<xsl:attribute name="MessagePriority"><xsl:value-of select="@MessagePriority"/></xsl:attribute>
				<xsl:apply-templates select="*|text()"/>
			</xsl:when>
			<xsl:when test="starts-with(name(),'Date_')">
				<xsl:call-template name="Ext:transform_datetime">
					<xsl:with-param name="Node"><xsl:value-of select="."/></xsl:with-param>
					<xsl:with-param name="Interface_Direction" select="$Interface_Direction"></xsl:with-param>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:copy-of select="@*"/>
				<xsl:apply-templates select="*|text()"/>
		  	</xsl:otherwise>
		</xsl:choose>
		</xsl:copy>
	</xsl:template>
	<!--			
	********************************************************************
	Template to transform the Date and Time format of nodes starting with 
	Date_ to standard XML Date Time Format based on ISO 8601 (Representations of 
	dates and times, 1988-06-15). For details on the format, please refer
	to the document "0769 Managed Evolution Integration Architecture.doc"
	********************************************************************
	-->	 
	<xsl:template name="Ext:transform_datetime">
		<xsl:param name="Node"/>
		<xsl:param name="Interface_Direction"/>
			<xsl:choose>
				<xsl:when test="$Interface_Direction='Siebel Outbound'">
					<xsl:variable name="Year" select="substring($Node,7,4)"/>
					<xsl:variable name="Month" select="substring($Node,4,2)"/>
					<xsl:variable name="Day" select="substring($Node,1,2)"/>
					<xsl:variable name="Time" select="substring($Node,12,8)"/>
					<xsl:value-of select="concat($Year, '-', $Month, '-', $Day, 'T', $Time, '+09:30')"/>
				</xsl:when>
				<xsl:when test="$Interface_Direction='Siebel Inbound'">
					<xsl:variable name="Year" select="substring($Node,1,4)"/>
					<xsl:variable name="Month" select="substring($Node,6,2)"/>
					<xsl:variable name="Day" select="substring($Node,9,2)"/>
					<xsl:variable name="Time" select="substring($Node,12,8)"/>
					<xsl:value-of select="concat($Day, '/', $Month, '/', $Year, ' ', $Time)"/>
				</xsl:when>
		 </xsl:choose>
	</xsl:template> 
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="no" externalpreview="no" url="file:///d:/oexml/test_lov/BeforeTransformOutboundSBLXml_2E&#x2D;20A&#x2D;Req.xml" htmlbaseurl="" outputurl="file:///d:/oexml/test_lov/test_xx.xml" processortype="xalan" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="..\dest.xsd" destSchemaRoot="SiebelMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="..\oexml_r1.xsd" srcSchemaRoot="OEXML" AssociatedInstance="file:///d:/oexml/test_a1.xml" loaderFunction="document" loaderFunctionUsesURI="no"/><SourceSchema srcSchemaPath="eai_value_map.xml" srcSchemaRoot="root" AssociatedInstance="file:///d:/oexml/test_lov/eai_value_map.xml" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition><template match="/"><block path="a:SiebelMessage/xsl:attribute[1]/xsl:for&#x2D;each/xsl:if/=[0]" x="217" y="70"/><block path="a:SiebelMessage/xsl:attribute[1]/xsl:for&#x2D;each/xsl:if" x="263" y="72"/></template><template match="*"></template></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->