<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="text"/>

	<xsl:variable name="new_line" select="'&#xA;'"/>

	<!--
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<FAC_melding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <TOPdesk>
      <Opdrachtnummer></Opdrachtnummer>
      <Mutatiecode></Mutatiecode>
      <Mutatietijdstip></Mutatietijdstip>
      <Externnr></Externnr>
      <Opmerking></Opmerking>
      <Einddatum></Einddatum>
    </TOPdesk>
</FAC_melding>
	-->
	<xsl:template match="/">
		<xsl:if test="FAC_melding/TOPdesk!=''">
OPDRACHTNUMMER;MUTATIECODE;MUTATIETIJDSTIP;EXTERNNR;OPMERKING;EINDDATUM<xsl:value-of select="$new_line"/>
			<xsl:for-each select="FAC_melding/TOPdesk">
<xsl:variable name="tekst_oms"><xsl:call-template name="StrReplace"><xsl:with-param name="string" select="Opmerking"/><xsl:with-param name="str1" select="'&#13;&#10;'"/><xsl:with-param name="str2" select="'%%0A'"/></xsl:call-template></xsl:variable>
<xsl:variable name="tekst_800"><xsl:value-of select="substring($tekst_oms,1,800)"/></xsl:variable>
<xsl:value-of select="Opdrachtnummer"/>;<xsl:value-of select="Mutatiecode"/>;<xsl:value-of select="Mutatietijdstip"/>;<xsl:value-of select="Externnr"/>;<xsl:value-of select="$tekst_800"/>;<xsl:value-of select="Einddatum"/><xsl:value-of select="$new_line"/>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<xsl:template name="StrReplace">
    <xsl:param name="string"/>
    <xsl:param name="str1"/>
    <xsl:param name="str2"/>
    <xsl:choose>
      <xsl:when test="contains($string, $str1)">
        <xsl:value-of select="substring-before($string, $str1)"/><xsl:value-of select="$str2"/>
        <xsl:call-template name="StrReplace">
          <xsl:with-param name="string" select="substring-after($string, $str1)"/>
          <xsl:with-param name="str1" select="$str1"/>
					<xsl:with-param name="str2" select="$str2"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$string"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
