<?xml version="1.0" encoding="UTF-8"?>
<!-- author: Herb Ramos VoiceRite Inc -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vx="http://www.w3.org/2001/vxml"
 xmlns:jsp="http://java.sun.com/JSP/Page" exclude-result-prefixes="vxml vx">


	<xsl:output method="xml" indent="yes" media-type="text/xml" omit-xml-declaration="yes"/>
	<!-- start with the root -->

	<xsl:template match="/">
		<xsl:comment> =============================================================== </xsl:comment>
		<xsl:comment> Copyright(c) 2005 transformed by VoiceRite Inc.</xsl:comment>
		<xsl:comment> =============================================================== </xsl:comment>
		<xsl:apply-templates select="node() | @*"/>
	</xsl:template>
	
	<!-- ================================================ TEMPLATE <property> ================================================-->
	<xsl:template match="vx:property">
		<xsl:choose>
			<!-- do not copy universals properties -->
			<xsl:when test="@name='universals'">	
			<xsl:comment> *** universals property element deleted *** </xsl:comment>
			</xsl:when>
			<!-- convert maxage property to document maxage-->
			<xsl:when test="@name='maxage'">			
				<xsl:element name="{local-name(.)}"  >
					<xsl:attribute name="name">documentmaxage</xsl:attribute>
					<xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute>
				</xsl:element>
			</xsl:when>
			<!-- copy the remaining properties -->
			<xsl:otherwise>
				<xsl:element name="{local-name(.)}">
					<!-- <xsl:copy-of select="namespace::*[not(. = 'vx')]"/> -->
					<xsl:copy-of select="@*"/>
					<!--<xsl:apply-templates/>-->
				</xsl:element>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- ================================================ TEMPLATE <prompt> ================================================-->
	<xsl:template match="vx:prompt">
		<!-- recreate the prompt element without the count attribute -->
		<!--<xsl:comment> *** count attribute deleted from prompt element *** </xsl:comment>-->
		<xsl:element name="{local-name()}">
			<xsl:for-each select="attribute::*"> 
				<xsl:if test="not (local-name() = '~~~~~count')"> 
					<xsl:variable name="attrName" select="local-name()"/> 
					<xsl:attribute name="{$attrName}"> 
						<xsl:value-of select="."/> 
					</xsl:attribute> 
				</xsl:if> 
			</xsl:for-each> 
		<xsl:apply-templates select="node()"/>
		</xsl:element>
	</xsl:template>

	<!-- ================================================ TEMPLATE <voice> ================================================-->
	<xsl:template match="vx:voice">
		<!-- remove the voice element and keep it's text-->
		<!--<xsl:comment> *** voice element deleted text node as follows *** </xsl:comment> -->
		<xsl:variable name="nodeValue"><xsl:value-of select="node()"/></xsl:variable> 
		<xsl:copy-of select="node()"/>
	</xsl:template>

	<!-- ================================================ TEMPLATE <log> ================================================-->
	<xsl:template match="vx:log">
		<!-- delete the log element -->
		<xsl:comment> *** log element deleted *** </xsl:comment>
	</xsl:template>

	<!-- ================================================ TEMPLATE <audio> ================================================-->
	<xsl:template match="vx:audio">
		<!-- recreate the audio element with no attributes -->
		<xsl:element name="{local-name(.)}">
			<xsl:copy-of select="attribute::*[not(. = 'src')]"/>
			<xsl:apply-templates select="node()"/>
			<!--<xsl:apply-templates/>-->
		</xsl:element>
	</xsl:template>

	<!-- ================================================ TEMPLATE <grammar> ================================================-->
	<xsl:template match="vx:grammar">
		<xsl:element name="{local-name(.)}" namespace="http://www.w3.org/2001/06/grammar">
			<!--<xsl:copy-of select="@*"/>-->
			<!-- <xsl:attribute name="xmlns">http://www.w3.org/2001/06/grammar</xsl:attribute>-->
			<xsl:apply-templates select="node() | @*"/>
		</xsl:element>
	</xsl:template>

	<!-- ================================================ TEMPLATE <item> ================================================-->
	<xsl:template match="vx:item">
		<xsl:choose>
			<xsl:when test="substring(@tag,1,11)= 'returnvalue' ">
				<xsl:element name="{local-name(.)}">
					<xsl:variable name="tagValue"><xsl:value-of select="substring(@tag, 14,  string-length(@tag) -14) "/></xsl:variable> 
					<xsl:variable name="nodeValue"><xsl:value-of select="node()"/></xsl:variable> 
					<xsl:attribute name="tag"><xsl:value-of select="$tagValue"/></xsl:attribute>   
					<xsl:text/><xsl:value-of select="$nodeValue"/><xsl:text/> 
				</xsl:element>
			</xsl:when>
			<xsl:otherwise>
				<xsl:apply-templates select="node() | @*"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<!-- ================================================ TEMPLATE node() | @* ================================================-->
	<xsl:template match="node() | @*" >
		<xsl:copy>
			<xsl:apply-templates select="node() | @*"/>
		</xsl:copy>
	</xsl:template>
</xsl:stylesheet>
