<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--	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. -->
<!--    Author of this style sheet: Ralf Herzog
        Date of creation: May 2010 -->


<!-- use (1) create-phoneme-fast # OR (2) create-phoneme-espeaktoipa OR (3) create-phoneme
<xsl:template name="create-phoneme-fast">
 <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><xsl:element name="phoneme">
  <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
  <xsl:sequence select="$sierra"/></xsl:element>
 </xsl:for-each>
</xsl:template> -->

<!-- May 2010 
<xsl:template name="convert-ascii-phonemes-to-ipa">

</xsl:template>-->

<!-- May 2010 -->
<xsl:template name="improve-quality-of-phonemes">
 <xsl:variable name="sierra-outside">
  <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text>
   <xsl:element name="phoneme"><!--
    <xsl:call-template name="convert-ascii-phonemes-to-ipa"/>-->
     <xsl:variable name="sierra">
  <xsl:value-of select="."/> <!-- this should select the current phoneme -->
 </xsl:variable>
 <!-- May 2010 -->
 <xsl:variable name="sierra" select="replace($sierra, 'vɐgaːbə', 'fɐgaːbə')"/>
 <xsl:variable name="sierra" select="replace($sierra, 'vɐkaʊ̯f', 'fɐkaʊ̯f')"/>
 <xsl:variable name="sierra" select="replace($sierra, 'vɐkeːʀ', 'fɐkeːʀ')"/>
 <xsl:variable name="sierra" select="replace($sierra, 'vɐtsiːɐ̯t', 'fɐt͡siːɐ̯t')"/>
 <xsl:variable name="sierra" select="replace($sierra, 'veːʀanstaltʊŋ', 'fɛʀanʃtaltʊŋ')"/>
 <xsl:variable name="sierra" select="replace($sierra, 'hœltsɐ', 'hœlt͡sɐ')"/>
 <xsl:sequence select="$sierra"/>
   </xsl:element>
  </xsl:for-each>
 </xsl:variable>
 <xsl:sequence select="$sierra-outside"/>

</xsl:template>

<!--20100207-->
<xsl:template name="create-phoneme">
 <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text>
  <element name="phoneme">
   <xsl:variable name="sierra">
    <xsl:value-of select="."/>
   </xsl:variable>
   <xsl:sequence select="$sierra"/>
  </element>
 </xsl:for-each>
</xsl:template>


<!--<xsl:template name="create-lexemewithrole"> 
 <xsl:param name="rolevalue"></xsl:param>
</xsl:template>

 20100404 -->
<xsl:template name="create-different-phonemes">
     <xsl:param name="iieren"></xsl:param>
     <xsl:variable name="different">
      <xsl:for-each select="phoneme">
       <xsl:value-of select="string-join((., $iieren), ' ')"/><xsl:text> </xsl:text>
      </xsl:for-each>
     </xsl:variable> 
     <xsl:variable name="different" select="tokenize(($different), ' ')"/>
     <xsl:for-each select="distinct-values($different)">
<xsl:if test="not(.='')">
<xsl:text>
   </xsl:text>
       <xsl:element name="phoneme">
        <xsl:value-of select="."/>
       </xsl:element>
</xsl:if>
     </xsl:for-each>
</xsl:template>


<xsl:template name="when-grapheme-contains-then-modify-phoneme">
  <xsl:choose>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'Holz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'hɔlts', 'hɔlt͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'holz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'hɔlts', 'hɔlt͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="ends-with(grapheme, 'ohr')">
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'oːʀ', 'oːɐ̯')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'Tanz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'tants', 'tant͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'tanz')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'tants', 'tant͡s')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'Medien')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'meːdiːn', 'meːdi̯ɛn')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'medien')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'meːdiːn', 'meːdi̯ɛn')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'ngeschicht')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'ŋɛʃɪçt', 'ngəʃɪçt')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, 'befehl')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'beːfeːl', 'bəfeːl')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  <!-- May 2010 -->
  <xsl:when test="contains(grapheme, '1')"> 
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'tseːn', 't͡seːn')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  


  <xsl:when test="ends-with(grapheme, 'gier')">
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'giːʀ', 'giːɐ̯')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  
    <xsl:when test="starts-with(grapheme, 'Depot')"><!--20100402-->
    <xsl:for-each select="phoneme"><xsl:text>
   </xsl:text><phoneme>
    <xsl:variable name="sierra"><xsl:value-of select="."/></xsl:variable>
    <xsl:variable name="sierra" select="replace($sierra, 'deːpɔt', 'deːpoː')"/>
    <xsl:sequence select="$sierra"/></phoneme>
    </xsl:for-each>
  </xsl:when>
  
  <xsl:otherwise>
    <xsl:call-template name="improve-quality-of-phonemes"/> 
  </xsl:otherwise>
  </xsl:choose>

</xsl:template>
<!-- May 2010 -->
<xsl:template match="lexicon"><xsl:text>
</xsl:text>
<xsl:comment>    Ralf's German dictionary (version 0.1.9.3; May 04, 2010)
        More than 300.000 words, needs improvement. 
        You can import this PLS dictionary into 'simon'. More info:
        http://spirit.blau.in/simon/tag/node16/ </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="de-DE">

<xsl:for-each-group select="lexeme" group-by="grapheme">
<!-- <xsl:sort select="grapheme" order="ascending"/> -->
 <!--<xsl:variable name="rolecontent" select="@role"></xsl:variable> 
 <xsl:call-template name="create-lexemewithrole">
  <xsl:with-param name="rolevalue" select="$rolecontent"/>
 </xsl:call-template>-->
<xsl:text>
 </xsl:text>
 <xsl:element name="lexeme">
  <xsl:attribute name="role" select="@role"/>
  <xsl:for-each select="grapheme">
   <xsl:call-template name="create-german-grapheme-element"/>
  </xsl:for-each>
  <xsl:variable name="modified">
   <xsl:call-template name="when-grapheme-contains-then-modify-phoneme"/>
  </xsl:variable><!--
  <xsl:variable name="modified">
   <xsl:call-template name="espeaktoipa-outside"/>
  </xsl:variable>-->
  <xsl:sequence select="$modified"/><xsl:text>
 </xsl:text>
 </xsl:element>
</xsl:for-each-group><xsl:text>
</xsl:text>
</lexicon>
</xsl:template>

<!-- May 2010 -->
<xsl:template name="create-german-grapheme-element">
 <xsl:variable name="current-grapheme">
 <xsl:text>
  </xsl:text>
  <xsl:element name="grapheme">
   <xsl:value-of select="."/>
  </xsl:element>
 </xsl:variable>
 <xsl:sequence select="$current-grapheme"/>
</xsl:template>

</xsl:stylesheet>

