<?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">fac_usrdata_code;fac_usrdata_omschr
<xsl:for-each select="node()/node()/node()/node()">
<xsl:if test="local-name() = 'CodeId'"> <xsl:value-of select="text()"/>;</xsl:if>
<xsl:if test="local-name() = 'Description'"><xsl:value-of select="text()"/>;
</xsl:if>
</xsl:for-each>
<xsl:for-each select="descendant::*/b:ReturnCode"><xsl:value-of select="CodeId"/>;<xsl:call-template name="puntkomma"><xsl:with-param name="p_string" select="Description"/></xsl:call-template>;&#10;</xsl:for-each>
</xsl:template>

<xsl:template name="puntkomma">
<xsl:param name="p_string"/><xsl:call-template name="linebreaks"><xsl:with-param name="string" select="translate($p_string,';',':')"/></xsl:call-template></xsl:template>

<xsl:template name="linebreaks">
    <xsl:param name="string"/>
    <xsl:choose>
      <xsl:when test="contains($string, '&#xA;')">
        <xsl:value-of select="substring-before($string, '&#xA;')"/>
        <br/>
        <xsl:call-template name="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>
