<?xml version="1.0" encoding="UTF-8"?>
<!--    Create Ralf's IPA style-sheet (version 0.1; May 11, 2010) -->
<!--	This style-sheet 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. -->
<!--    Created in May 2010 by Ralf Herzog -->

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:axsl="createnewxsl">
<!--<xsl:output method="text"/>

 <xsl:character-map name="less-than-sign">
  <xsl:output-character character="&lt;" string="lessthansign"></xsl:output-character>
 </xsl:character-map>
-->
<xsl:namespace-alias result-prefix="xsl" stylesheet-prefix="axsl"/>

<xsl:template match="espeakphonemetable"><xsl:text>
</xsl:text><xsl:comment>    Ralf's IPA style-sheet (version 0.1; May 11, 2010) </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 is licensed under the GPLv3.
        Read the full license text: http://script.blau.in/etc/GPL_License </xsl:comment><xsl:text>
</xsl:text>
<axsl:stylesheet version="2.0" 
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:text>
</xsl:text><axsl:template match="lexicon"><axsl:text><xsl:text>
</xsl:text></axsl:text><axsl:comment>    Ralf's IPA dictionary (version 0.1; May 11, 2010)
        You can import this dictionary into 'simon'. </axsl:comment><axsl:text><xsl:text>
</xsl:text></axsl:text>
<axsl: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. </axsl:comment><axsl:text><xsl:text>
</xsl:text></axsl:text>
<axsl:comment>	This PLS dictionary is licensed under the GPLv3.
        Read the full license text: http://script.blau.in/etc/GPL_License </axsl:comment><axsl:text>
<xsl:text>
</xsl:text>
 </axsl:text><xsl:text>
</xsl:text><axsl:element name="lexicon">
<axsl:attribute name="version"><xsl:text>1.0</xsl:text></axsl:attribute><xsl:text>
</xsl:text><axsl:attribute name="alphabet"><xsl:text>ipa</xsl:text></axsl:attribute><xsl:text>
</xsl:text><axsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/><axsl:value-of select="@xml:lang"/></axsl:attribute>
<axsl:text><xsl:text>
 </xsl:text></axsl:text>
<xsl:text>
 </xsl:text><axsl:for-each select="lexeme"><xsl:text>
 </xsl:text><axsl:element name="lexeme"><axsl:text><xsl:text>
 </xsl:text></axsl:text><xsl:text>
   </xsl:text><axsl:call-template name="display-grapheme-element"/><axsl:text><xsl:text>
  </xsl:text></axsl:text><xsl:text>
   </xsl:text><axsl:element name="phoneme"><xsl:text>
  </xsl:text><axsl:call-template name="show-espeaktoipa-element"/><xsl:text>
 </xsl:text></axsl:element><axsl:text><xsl:text><!-- phoneme -->
</xsl:text></axsl:text><xsl:text>
  </xsl:text></axsl:element><axsl:text><xsl:text><!-- lexeme -->
  </xsl:text></axsl:text><xsl:text>
 </xsl:text></axsl:for-each><axsl:text><xsl:text>
 </xsl:text></axsl:text><xsl:text>
  </xsl:text></axsl:element><axsl:text><xsl:text><!-- lexicon -->
</xsl:text></axsl:text>



 
 </axsl:template>
 
 
  <xsl:text>
</xsl:text><xsl:text>
</xsl:text><axsl:template name="display-grapheme-element"><xsl:text>
 </xsl:text><axsl:element name="grapheme"><xsl:text>
 </xsl:text><axsl:value-of select="grapheme"/><xsl:text>
 </xsl:text></axsl:element><xsl:text>
 </xsl:text></axsl:template>
 <xsl:text>
</xsl:text>
  
 <xsl:text>
</xsl:text><axsl:template name="show-espeaktoipa-element"><xsl:text>
</xsl:text> <axsl:variable name="espeak2ipa"><xsl:text>
 </xsl:text><axsl:value-of select="phoneme"/><xsl:text>
 </xsl:text> </axsl:variable><xsl:text>
</xsl:text>
<!-- remove later 
<axsl:if test="matches(/lexicon/@xml:lang, 'nl')" and test="matches(/lexicon/@alphabet, 'espeak')">
 <axsl:value-of select="/lexicon/@xml:lang"/>matchednl-matchedespeak 
</axsl:if>-->

 <xsl:text>
</xsl:text> <axsl:variable name="espeak2ipa"><xsl:text>
 </xsl:text><axsl:choose><xsl:text>
 </xsl:text>


<xsl:for-each select="dictionary">
  <xsl:call-template name="create-latin-lexeme-element"/>
</xsl:for-each><xsl:text>
 </xsl:text><axsl:otherwise><xsl:text>
 </xsl:text> <axsl:sequence select="$espeak2ipa"/><axsl:text><xsl:text>otherwisenode</xsl:text></axsl:text>

 </axsl:otherwise><xsl:text>
</xsl:text></axsl:choose><xsl:text>
 </xsl:text></axsl:variable><xsl:text>
 </xsl:text><axsl:sequence select="$espeak2ipa"/><xsl:text>
 </xsl:text>
 </axsl:template><xsl:text>
 </xsl:text>
 
 
 
</axsl:stylesheet>
</xsl:template>

<xsl:template name="create-latin-lexeme-element">
 <xsl:variable name="current-latin-lexeme">  
<xsl:text>
 </xsl:text>
 <axsl:when>
    <xsl:attribute name="test">
     <xsl:text>matches(/lexicon/@xml:lang, '</xsl:text>
     <xsl:sequence select="normalize-space(languagetag)"/>
     <xsl:text>')</xsl:text>
    </xsl:attribute>

 
 <xsl:text>
 </xsl:text>

  <xsl:for-each select="espeakphoneme">
   <xsl:choose>
    <xsl:when test="not(string(.))"/>
    <xsl:otherwise>
     <xsl:call-template name="generate-replace-expression"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
<xsl:text> </xsl:text>
 <axsl:sequence select="$espeak2ipa"/><xsl:text>
 </xsl:text>
 </axsl:when>
 </xsl:variable>
 <xsl:sequence select="$current-latin-lexeme"/>
</xsl:template>

<xsl:template name="generate-replace-expression">
 <xsl:variable name="current-espeak">
  <xsl:value-of select="normalize-space(.)"/>
 </xsl:variable>
 <xsl:variable name="current-espeak" select="replace($current-espeak, '\*', '\\*')"/>
 <xsl:variable name="current-espeak" select="replace($current-espeak, '\?', '\\?')"/>
 <xsl:variable name="current-espeak" select="replace($current-espeak, 'i\[', 'i\\[')"/>
 <xsl:variable name="current-espeak" select="replace($current-espeak, 't\[', 't\\[')"/>


  <xsl:variable name="current-ipa">
  <xsl:value-of select="normalize-space(.)"/>
 </xsl:variable>
 <xsl:variable name="current-ipa" select="replace($current-ipa, 'a:', 'aː')"/>
<xsl:variable name="current-ipa" select="replace($current-ipa, 'e:', 'eː')"/>
<xsl:variable name="current-ipa" select="replace($current-ipa, 'i:', 'iː')"/>
<xsl:variable name="current-ipa" select="replace($current-ipa, 'o:', 'oː')"/>
<xsl:variable name="current-ipa" select="replace($current-ipa, 'u:', 'uː')"/>
<xsl:variable name="current-ipa" select="replace($current-ipa, 'EI', 'ɛɪ̯')"/> 
<!-- compare with Wiktionary: "Lady /[ˈlɛɪ̯di]/, E-Mail /[ˈiːˌmɛɪ̯l]/, hey /[hɛɪ̯]/" -->
<xsl:variable name="current-ipa" select="replace($current-ipa, '@', 'ə')"/> 
<xsl:variable name="current-ipa" select="replace($current-ipa, 'E', 'ɛ')"/> 
 <axsl:variable name="espeak2ipa">
  <xsl:attribute name="select">
   <xsl:text>replace($espeak2ipa, '</xsl:text>
   <xsl:sequence select="$current-espeak"/>
   <xsl:text>', '</xsl:text>
   <xsl:sequence select="$current-ipa"/>
   <xsl:text>')</xsl:text>
  </xsl:attribute>
 </axsl:variable><xsl:text>
</xsl:text>



</xsl:template>





</xsl:stylesheet>

