<?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" encoding="UTF-8"/>


<xsl:template match="/">
<xsl:comment>leveranciernr(leeg);factuurnr;factuurdatum;opdrachtnr;locatie(leeg);afleverdatum(leeg);omschrijving;aantal(leeg);bedrag;btwbedrag(leeg);btwperc;document(leeg);debiteur_nr(leeg);opmerking(leeg);btw-verlegd;kenmerk1 (= naam PDF bestand);kenmerk6 status uitval;kenmerk7 opmerking uitval;kenmerk8 bron code xml pdf keten;kenmerk9 bron_text;kenmerk10 intern bedrijfsherkenning </xsl:comment>
<xsl:for-each select="fin_factuur"><xsl:for-each select="fin_factuurregel">;<xsl:value-of select="../fin_factuur_nr"/>;<xsl:value-of select="../fin_factuur_datum"/>;<xsl:value-of select="../mld_bes_opdracht_nr"/>;;;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="fin_factuurregel_omschrijving"/></xsl:call-template>;;<xsl:value-of select="fin_factuurregel_totaal"/>;;<xsl:value-of select="fin_factuurregel_btwperc"/>;;;;<xsl:call-template name="BTW_verlegd"/>;<xsl:value-of select="../Attachment/FileName"/>;;;;;;<xsl:value-of select="../fin_factuur_statuses_key"/>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="../fin_factuur_opmerking"/></xsl:call-template>;<xsl:value-of select="../marx_factuur_bron"/>;<xsl:call-template name="vrije_tekst"><xsl:with-param name="p_string" select="../marx_factuur_bron_txt"/></xsl:call-template>;<xsl:value-of select="../prs_bedrijf_id"/>;&#10;</xsl:for-each></xsl:for-each>
</xsl:template>

<xsl:template name="BTW_verlegd">
	<xsl:choose>
    <xsl:when test="fin_factuurregel_btwverlegd = '1'">Ja</xsl:when>
   	<xsl:otherwise></xsl:otherwise>
  </xsl:choose>	
</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:stylesheet>