Answer the question
In order to leave comments, you need to log in
XSL transformation -> CSV -> how to replace newline character?
Good afternoon!
There is an extension that converts data from XML to CSV.
In the fields "S_Street" and "R_Street" there are data in several lines, which of course breaks the CSV format.
Please tell me. how to replace the newline character in the "S_Street" and "R_Street" fields with a semicolon (" ,").
Thank you.
Here it is not possible to insert the code itself, since the message format breaks. Link: https://drive.google.com/file/d/0B8P7x0eHO8zNNmtuS...
Answer the question
In order to leave comments, you need to log in
Without regex like this:
<documentRecipientAddressData>
<street>Centroallee 1000
Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...</street>
<street>Centroallee
1000
Einfahrt
Parkhaus 7 an der
"Alten Waltz" gegenüber Tryp Hotel ...</street>
<street>Centroallee 1000 Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...</street>
</documentRecipientAddressData>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/documentRecipientAddressData/street">
<xsl:variable name="street">
<xsl:call-template name="replace-line-breaks">
<xsl:with-param name="text">
<xsl:call-template name="normalize-line-breaks">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="normalize-space($street)"/>
<xsl:text>
</xsl:text>
<xsl:variable name="street">
<xsl:call-template name="normalize-line-breaks">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="replace($street, '\n', ', ')"/>
<xsl:text>

</xsl:text>
</xsl:template>
<xsl:template name="replace-line-breaks">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="not(contains($text, '
'))">
<xsl:value-of select="$text"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($text, '
')"/>
<xsl:text>, </xsl:text>
<xsl:call-template name="replace-line-breaks">
<xsl:with-param name="text" select="substring-after($text, '
')"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="normalize-line-breaks">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="not(contains($text, '

'))">
<xsl:value-of select="$text"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="text">
<xsl:value-of select="substring-before($text, '

')"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="substring-after($text, '

')"/>
</xsl:variable>
<xsl:call-template name="normalize-line-breaks">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Centroallee 1000, Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee 1000, Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee, 1000, Einfahrt, Parkhaus 7 an der, "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee, 1000, Einfahrt, Parkhaus 7 an der, "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee 1000 Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
Centroallee 1000 Einfahrt Parkhaus 7 an der "Alten Waltz" gegenüber Tryp Hotel ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question