<?xml version="1.0" encoding="UTF-8"?>
<!--	This style-sheet "improve-[language]-dictionary.xsl" is licensed under the GPLv3.
        Read the full license text: http://script.blau.in/etc/GPL_License -->
<!--    This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 3 of the License, or
        (at your option) any later version.
        
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
        
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
        MA 02110-1301, USA. -->
<!--    201004 -->
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="lexicon"><xsl:text>
</xsl:text><xsl:comment>    Ralf's Estonian dictionary (version 0.1; April 20, 2010)
        You can import this dictionary into 'simon'.
        This PLS dictionary serves as a first draft. 
        More info: http://spirit.blau.in/simon/tag/node31 </xsl:comment><xsl:text>
</xsl:text>
<xsl:comment>    This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 3 of the License, or
        (at your option) any later version.
        
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
        
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
        MA 02110-1301, USA. </xsl:comment><xsl:text>
</xsl:text>
<xsl:comment>	This PLS dictionary is licensed under the GPLv3.
        Read the full license text: http://script.blau.in/etc/GPL_License </xsl:comment><xsl:text>
</xsl:text>
<lexicon version="1.0" alphabet="ipa" xml:lang="et">

<xsl:for-each-group select="lexeme" group-by="grapheme">
 <xsl:sort select="grapheme" order="ascending"/>
 <xsl:call-template name="create-latin-lexeme-element"/>
</xsl:for-each-group><xsl:text>
</xsl:text>
</lexicon>
</xsl:template>

<xsl:template name="create-latin-lexeme-element">
 <xsl:variable name="current-latin-lexeme">  
 <xsl:text>
 </xsl:text>
 <xsl:element name="lexeme">
  <xsl:call-template name="create-latin-grapheme-element"/>
  <xsl:call-template name="create-assamese-phoneme-element"/><xsl:text>
 </xsl:text>
 </xsl:element>
 </xsl:variable>
 <xsl:sequence select="$current-latin-lexeme"/>
</xsl:template>

<xsl:template name="create-latin-grapheme-element">
 <xsl:variable name="current-grapheme">
  <xsl:choose>
  <xsl:when test="contains(grapheme, '/')">
   <xsl:value-of select="substring-before(grapheme, '/')"/>
  </xsl:when>
  <xsl:otherwise>
   <xsl:value-of select="grapheme"/>
  </xsl:otherwise>
  </xsl:choose>
 </xsl:variable><xsl:text>
  </xsl:text>
 <xsl:element name="grapheme"><xsl:sequence select="$current-grapheme"/></xsl:element>
</xsl:template>

<xsl:template name="create-assamese-phoneme-element">
 <xsl:variable name="current-grapheme">
  <xsl:choose>
  <xsl:when test="contains(grapheme, '/')">
   <xsl:value-of select="substring-before(grapheme, '/')"/>
  </xsl:when>
  <xsl:otherwise>
   <xsl:value-of select="grapheme"/>
  </xsl:otherwise>
  </xsl:choose>
 </xsl:variable>
 <xsl:variable name="current-grapheme" select="lower-case($current-grapheme)"/>
 <!-- http://en.wikipedia.org/wiki/Danish_phonology#Orthography 

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'aa', 'å')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ae', 'æ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ä', 'æ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'au', 'aʊ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'aw', 'aʊ̯')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ai', 'aɪ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ay', 'aɪ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'bb', 'b̥')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'b', 'b̥')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'cc', 'ks')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ch', 'tɕ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'c', 'k')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'dd', 'd̥')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'd', 'd̥')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ea', 'i')"/>

<xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ee', 'i')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'eg', 'aɪ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ei', 'aɪ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ej', 'aɪ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ff', 'f')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'gg', 'ɡ̊')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'g', 'ɡ̊')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ie', 'i')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'kk', 'k')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'll', 'l')"/>

  <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ld', 'l')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'mm', 'm')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'nn', 'n')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'nd', 'n')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ng', 'ŋ')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'oe', 'ø')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ö', 'ø')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'oo', 'u')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ou', 'aʊ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ow', 'aʊ̯')"/>

<xsl:variable name="current-grapheme" select="replace($current-grapheme, 'pp', 'p')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ph', 'f')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'rr', 'ʁ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'rd', 'ɐ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ss', 's')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'sj', 'ɕ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'sch', 'ɕ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'sh', 'ɕ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'tt', 't')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'th', 't')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ue', 'y')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ü', 'y')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'v', 'ʋ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'w', 'v')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'x', 'ɡ̊s')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'zz', 's')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'z', 's')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'æ', 'ɛ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'øg', 'aɪ̯')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'øj', 'aɪ̯')"/>

  <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'å', 'a')"/>-->
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, '-', '')"/>
 <!--<xsl:variable name="current-grapheme" select="replace($current-grapheme, ''', '')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ю', 'ju')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Я', 'ja')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'я', 'ja')"/>-->
<xsl:text>
   </xsl:text> <xsl:element name="phoneme"> 
  <xsl:sequence select="$current-grapheme"/>
 </xsl:element>
</xsl:template>

</xsl:stylesheet>

