<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                version="1.0">
<xsl:output method="text" encoding="UTF-8"/>


<xsl:template match="/">
<xsl:apply-templates select="soap:Envelope/soap:Body"/>
</xsl:template>

<xsl:template match="soap:Body">ax_supplier_id;mld_melding_externnr;mld_melding_omschrijving;prs_afdeling_externnr;mld_melding_cust_name;mld_melding_cust_straat;mld_melding_cust_huisnr;mld_melding_cust_huisnr2;mld_melding_cust_postcode;mld_melding_cust_plaats;mld_melding_cust_telefoonnr;mld_melding_cust_mobielnr;mld_melding_cust_object_omschr;mld_melding_memo;mld_opdr_externnr;mld_opdr_ordernr;mld_opdr_datumbegin;mld_opdr_datum_plan;mld_opdr_einddatum
<xsl:for-each select="descendant::*/Bon"><xsl:value-of select="CrediteurNummer"/>;<xsl:value-of select="BonNummer"/>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="BonOmschrijving"/></xsl:call-template>;1;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="HuurderNaam"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="StraatNaam"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="HuisNummer"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="Toevoegsel"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="Postcode"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="Woonplaats"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="Telefoon"/></xsl:call-template>;;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="xxx_objectDescription"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="xxx_memo"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="concat(BonNummer,'.',BonVolgNummer)"/></xsl:call-template>;<xsl:value-of select="BonId"/>;<xsl:value-of select="substring(BonDatumOpdracht,1,10)"/>;;<xsl:call-template name="Tobias_UitersteDatumGereed"><xsl:with-param name="p_datum" select="substring(UitersteDatumGereed,1,10)"/></xsl:call-template>;&#10;</xsl:for-each>
</xsl:template>

<xsl:template name="vrije_tekst">
<xsl:param name="p_string"/>
<xsl:variable name="l_string_esc_quotes"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="$p_string"/></xsl:call-template></xsl:variable>
<xsl:variable name="l_string_esc_linebreaks"><xsl:call-template name="escape_linebreaks"><xsl:with-param name="string" select="$l_string_esc_quotes"/></xsl:call-template></xsl:variable>"<xsl:value-of select="$l_string_esc_linebreaks"/>"</xsl:template>

<xsl:template name="escape_quote">
		<xsl:param name="string"/>
		<xsl:choose>
			<xsl:when test="contains($string, '&quot;')"><xsl:value-of select="substring-before($string, '&quot;')"/>&quot;&quot;<xsl:call-template name="escape_quote">
					<xsl:with-param name="string" select="substring-after($string, '&quot;')"/></xsl:call-template></xsl:when>
			<xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise>
		</xsl:choose>
</xsl:template>


<xsl:template name="escape_linebreaks">
		<xsl:param name="string"/>
		<xsl:choose>
			<xsl:when test="contains($string, '&#xA;')"><xsl:value-of select="substring-before($string, '&#xA;')"/>@@<xsl:call-template name="escape_linebreaks">
					<xsl:with-param name="string" select="substring-after($string, '&#xA;')"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise><xsl:value-of select="$string"/></xsl:otherwise>
		</xsl:choose>
</xsl:template>


<xsl:template name="Tobias_UitersteDatumGereed">
  	<xsl:param name="p_datum"/>
  	<xsl:choose>
			<xsl:when test="$p_datum = '1899-12-30'">2099-12-31</xsl:when>
  		<xsl:otherwise><xsl:value-of select="$p_datum"/></xsl:otherwise>
  	</xsl:choose>
</xsl:template>

</xsl:stylesheet>