<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--    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. -->
<!--	This style-sheet "improve-[language]-dictionary.xsl" is licensed under the GPLv3.
	    Read the full license text: http://script.blau.in/etc/GPL_License -->
<!--    201004 -->


<xsl:template match="lexicon"><xsl:text>
</xsl:text><!-- 201004 --><xsl:comment>    Ralf's Bulgarian dictionary (version 0.1; April 17, 2010)
        You can import this dictionary into 'simon'.
        This PLS dictionary serves as a first draft. </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="bg">

<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:text>
  </xsl:text>
  <xsl:element name="grapheme">
   <xsl:value-of select="grapheme"/>
  </xsl:element>
 </xsl:variable>
 <xsl:sequence select="$current-grapheme"/>
</xsl:template>

<xsl:template name="create-assamese-phoneme-element">
 <xsl:variable name="current-grapheme">
  <xsl:value-of select="grapheme"/>
 </xsl:variable>
<!-- Bulgarian vowel conversion: http://en.wikipedia.org/wiki/Bulgarian_language#Vowels -->
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'А', 'a')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'e', 'ɛ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'и', 'i')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ъ', 'ɤ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'у', 'u')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'о', 'ɔ')"/>

<!-- Bulgarian consonant conversion: http://en.wikipedia.org/wiki/Bulgarian_language#Alphabet -->
<!--  -->
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Б', 'b')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'б', 'b')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'В', 'v')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'в', 'v')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Г', 'g')"/>
<!--  -->
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'г', 'g')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Д', 'd')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'д', 'd')"/>
 <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, 'ж', 'ʒ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'З', 'z')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'з', 'z')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'И', 'i')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'и', 'i')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Й', 'j')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'й', 'j')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'К', 'k')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'к', 'k')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Л', 'l')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'л', 'l')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'М', 'm')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'м', 'm')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Н', 'n')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'н', 'n')"/>
 <!--   -->
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'О', 'o')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'П', 'p')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'п', 'p')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Р', 'r')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'р', 'r')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'С', 's')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'с', 's')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Т', 't')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'т', 't')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'У', 'u')"/>

 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'у', 'u')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Ф', 'f')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ф', 'f')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Х', 'x')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'х', 'x')"/>
  <!--  sdfgsdf -->
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Ц', 'ts')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ц', 'ts')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Ч', 'tʃ')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ч', 'tʃ')"/>
 <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, 'Щ', 'ʃt')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'щ', 'ʃt')"/>
 <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, 'Ь', 'j')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'ь', 'j')"/>
 <xsl:variable name="current-grapheme" select="replace($current-grapheme, 'Ю', 'ju')"/>
 <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>

