<?xml version="1.0" encoding="UTF-8"?>
<!--	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
        This style-sheet was used for the creation of Ralf's Occitan dictionary:
        http://spirit.blau.in/simon/tag/node45/ -->

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="newline-to-grapheme">
<xsl:param name="grapheme-or-audio"></xsl:param>
<xsl:text>
</xsl:text><xsl:element name="audio">  <xsl:analyze-string select="." regex="\n\n ">
  <xsl:matching-substring><xsl:text disable-output-escaping="yes">&lt;/audio&gt;
 &lt;audio&gt;</xsl:text></xsl:matching-substring>
  <xsl:non-matching-substring>
    <xsl:value-of select="."/>
  </xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:element>
</xsl:template>

<xsl:template name="replace-newline-by-audio-element">
<xsl:text>
</xsl:text><xsl:element name="audio">  <xsl:analyze-string select="." regex="\n">
  <xsl:matching-substring><xsl:text disable-output-escaping="yes">&lt;/audio&gt;
 &lt;audio&gt;</xsl:text></xsl:matching-substring>
  <xsl:non-matching-substring>
    <xsl:value-of select="."/>
  </xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:element>
</xsl:template>

<xsl:template name="replace-newline-newline-space-by-phoneme-element">
<xsl:text>
</xsl:text><xsl:element name="phoneme">  <xsl:analyze-string select="." regex="\n\n ">
  <xsl:matching-substring><xsl:text disable-output-escaping="yes">&lt;/phoneme&gt;
 &lt;phoneme&gt;</xsl:text></xsl:matching-substring>
  <xsl:non-matching-substring>
    <xsl:value-of select="."/>
  </xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:element>
</xsl:template>

<xsl:template name="replace-newline-by-lexeme-grapheme-element">
<xsl:text>
</xsl:text><xsl:element name="lexeme">  <xsl:element name="grapheme"><xsl:analyze-string select="." regex="\n">
  <xsl:matching-substring><xsl:text disable-output-escaping="yes">&lt;/grapheme&gt;&lt;/lexeme&gt;
 &lt;lexeme&gt;&lt;grapheme&gt;</xsl:text></xsl:matching-substring>
  <xsl:non-matching-substring>
    <xsl:value-of select="."/>
  </xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:element></xsl:element>
</xsl:template>

<xsl:template match="lexicon"><xsl:text>
</xsl:text>
 <xsl:element name="lexicon">
  <xsl:call-template name="replace-newline-newline-space-by-phoneme-element">
  </xsl:call-template>
 </xsl:element>
</xsl:template>

</xsl:stylesheet>

