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

	<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:variable name="new_line" select="'&#xA;'"/>

	<xsl:template match="/">
		<xsl:for-each select="BUSPARTNER/item">
			<xsl:variable name="imp_line">
&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="BUSPARTNER"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="NAAM"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESBEZOEK/item/ADRES"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESBEZOEK/item/POSTC"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESBEZOEK/item/PLAATS"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESBEZOEK/item/LAND"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESPOST/item/POSTBUS"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESPOST/item/PB_POSTC"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESPOST/item/PB_PLAATS"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ADRESPOST/item/PB_LAND"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="TELEFOON"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="FAX"/></xsl:call-template>&quot;;<xsl:value-of select="$new_line"/>
			</xsl:variable>
			<!--xsl:value-of select="substring($imp_line,1,990)"/-->
			<xsl:value-of select="$imp_line"/>
		</xsl:for-each>
		<xsl:for-each select="CASE/item">
			<xsl:choose>
				<xsl:when test="count(MARKTPARTIJ/item)=0">
					<xsl:variable name="imp_line">
&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ZAAKID"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="CONTRACTTYPE"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ZAAKSOORT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="CONTRACTANT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="INKGROEP"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="INKGOMS"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="RAAMCONTRACT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ONDERWERP"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="OPDRACHTDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="STARTWERKDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="EINDDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="UITACTIEDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTVERL"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="STATUS"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="CONTRFASE"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ZAAKBEHAND"/></xsl:call-template>&quot;;&quot;<xsl:for-each select="ACTOR/item"><xsl:if test="ACTORROL='ROL01'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="ACTOR/item"><xsl:if test="ACTORROL='ROL05'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="ACTOR/item"><xsl:if test="ACTORROL='ROL07'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="ACTOR/item"><xsl:if test="ACTORROL='ROL08'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="VERZGEB/item"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="VERZGINKGOMS"/></xsl:call-template>@</xsl:for-each>&quot;;&quot;<xsl:for-each select="INKSEGM/item"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="INKSEGMOMS"/></xsl:call-template>:<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="PERCENTAGE"/></xsl:call-template>@</xsl:for-each>&quot;;;<xsl:value-of select="$new_line"/>
					</xsl:variable>
					<!--xsl:value-of select="substring($imp_line,1,990)"/-->
					<xsl:value-of select="$imp_line"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:for-each select="MARKTPARTIJ/item">
						<xsl:variable name="imp_line">
&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/ZAAKID"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/CONTRACTTYPE"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/ZAAKSOORT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/CONTRACTANT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/INKGROEP"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/INKGOMS"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/RAAMCONTRACT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/ONDERWERP"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/OPDRACHTDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/STARTWERKDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/EINDDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/UITACTIEDAT"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/ACTVERL"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/STATUS"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/CONTRFASE"/></xsl:call-template>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ancestor::item/ZAAKBEHAND"/></xsl:call-template>&quot;;&quot;<xsl:for-each select="ancestor::item/ACTOR/item"><xsl:if test="ACTORROL='ROL01'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="ancestor::item/ACTOR/item"><xsl:if test="ACTORROL='ROL05'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="ancestor::item/ACTOR/item"><xsl:if test="ACTORROL='ROL07'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="ancestor::item/ACTOR/item"><xsl:if test="ACTORROL='ROL08'"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="ACTORID"/></xsl:call-template></xsl:if></xsl:for-each>&quot;;&quot;<xsl:for-each select="ancestor::item/VERZGEB/item"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="VERZGINKGOMS"/></xsl:call-template>@</xsl:for-each>&quot;;&quot;<xsl:for-each select="ancestor::item/INKSEGM/item"><xsl:call-template name="escape_quote"><xsl:with-param name="string" select="INKSEGMOMS"/></xsl:call-template>:<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="PERCENTAGE"/></xsl:call-template>@</xsl:for-each>&quot;;&quot;<xsl:call-template name="escape_quote"><xsl:with-param name="string" select="BUSPARTNER"/></xsl:call-template>&quot;;<xsl:value-of select="$new_line"/>
						</xsl:variable>
						<!--xsl:value-of select="substring($imp_line,1,990)"/-->
					  <xsl:value-of select="$imp_line"/>
					</xsl:for-each>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
