<?xml version="1.0"?>
<!-- <!DOCTYPE stylesheet [ <!ENTITY nbsp " "> ]> -->
<!--
	Author: Andrei Popescu-Belis
	File: idiap-to-sda-uet.xsl
	Date: 20 May 2003
	Purpose: Convert directly from IDIAP files (transcript.xml and agenda.rt) to SDA-UET.
	The goal is to be able to display nicely the IDIAP transcript.
	The problem is that there is no segmentation into utterances in the initial file, so this must be inferred (likely to be unaccurate).
	Also an instruction about episodes, to be derived from a (modified) agenda.rt file.

	i cut:  doctype-system="dialog-sda-10.dtd"

-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
<xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/Trans">
	<dialog>
	<xsl:apply-templates select="./Episode/Section/Turn"/>
	<xsl:call-template name="generate-episodes"/>
	</dialog>
</xsl:template>


<xsl:template match="Turn">
	<xsl:call-template name="generate-channel"><xsl:with-param name="speaker_id" select="0"/></xsl:call-template>
	<xsl:call-template name="generate-channel"><xsl:with-param name="speaker_id" select="1"/></xsl:call-template>
	<xsl:call-template name="generate-channel"><xsl:with-param name="speaker_id" select="2"/></xsl:call-template>
	<xsl:call-template name="generate-channel"><xsl:with-param name="speaker_id" select="3"/></xsl:call-template>
</xsl:template>


<xsl:template name="generate-channel">
<xsl:param name="speaker_id"/>
<channel>
	<xsl:attribute name="startTime"><xsl:value-of select="@startTime"/></xsl:attribute>
	<xsl:attribute name="endTime"><xsl:value-of select="@endTime"/></xsl:attribute>
	<xsl:attribute name="speaker"/>
	<xsl:attribute name="id"><xsl:value-of select="$speaker_id"/></xsl:attribute>
	<xsl:apply-templates select="Sync[@chan=$speaker_id]"/>
</channel>
<xsl:comment> **************************** </xsl:comment>
</xsl:template>


<xsl:template match="Sync">
<xsl:variable name="my_chan" select="@chan"/>
<xsl:choose>
<xsl:when test="normalize-space(following::text()[1])='GAP(OTHER)'"/>
<xsl:when test="normalize-space(following::text()[1])='SKIP(OTHER)'"/>
<xsl:when test="normalize-space(following::text()[1])='..'"/>
<xsl:when test="normalize-space(following::text()[1])=''"/>
<xsl:otherwise>
	<utt>
	<xsl:attribute name="startTime"><xsl:value-of select="@time"/></xsl:attribute>
	<xsl:attribute name="endTime"><xsl:value-of select="following::Sync[(position()=1) and @chan=$my_chan]/@time"/></xsl:attribute>
	<xsl:attribute name="id"><xsl:value-of select="$my_chan"/>_<xsl:number count="Sync[(@chan=$my_chan) and (normalize-space(following::text()[1])!='GAP(OTHER)') and (normalize-space(following::text()[1])!='SKIP(OTHER)') and (normalize-space(following::text()[1])!='..') and (normalize-space(following::text()[1])!='')]"/>
	</xsl:attribute>
	<xsl:element name="Sync"><xsl:attribute name="time"><xsl:value-of select="@time"/></xsl:attribute></xsl:element>
	<xsl:apply-templates select="following::text()[1]"/>
	</utt>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="text()[normalize-space(.)='GAP(OTHER)']">..</xsl:template> 
<xsl:template match="text()[normalize-space(.)='SKIP(OTHER)']">..</xsl:template> 


<xsl:template name="generate-episodes">
<episodes>

</episodes>
</xsl:template>

</xsl:stylesheet>

