<?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:s="http://www.w3.org/2003/05/soap-envelope"
                xmlns:b="http://schemas.datacontract.org/2004/07/SG.Services.Repositories" 
                xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
                version="1.0">
<xsl:output method="text" encoding="UTF-8"/>


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

<xsl:template match="s: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::*/b:SupplierTaskSpec"><xsl:value-of select="b:vendAccountNum"/>;<xsl:value-of select="b:requestId"/>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:description"/></xsl:call-template>;<xsl:value-of select="b:companyId"/>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:custName"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:custStreet"/></xsl:call-template>;;;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:custZipCode"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:custCity"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:custPhone"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:custMobilePhone"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:objectDescription"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:memo"/></xsl:call-template>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="b:purchId"/></xsl:call-template>;<xsl:value-of select="b:taskId"/>;<xsl:value-of select="b:registrationDate"/>;<xsl:call-template name="mld_opdr_plandatum"><xsl:with-param name="p_task_status" select="b:taskStatus"/><xsl:with-param name="p_plan_datum" select="b:startDateTime"/></xsl:call-template>;<xsl:value-of select="b:deadlineDate"/>;&#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="mld_melding_externnr">
		<!-- meldingnummer in TobiasAX wordt niet expliciet meegegeven, en wordt daarom afgeleid uit task-id, namelijk alles voor het koppelteken). -->
		<xsl:param name="p_string"/>
		<xsl:value-of select="substring-before($p_string, '-')"/>
</xsl:template>

<xsl:template name="mld_opdr_plandatum">
  	<xsl:param name="p_task_status"/>
  	<xsl:param name="p_plan_datum"/>
  	<xsl:if test="$p_task_status='Gepland'"><xsl:value-of select="$p_plan_datum"/></xsl:if>
</xsl:template>
  
</xsl:stylesheet>
