I have a string that looks like this: some, , , , text
I need it to look like this: some, text
There is unknown number of such commas, it may be 2, it may be 10
I tried recursive approach but it did not work as expected:
<xsl:template name="remove-duplicate">
<xsl:param name="text" />
<xsl:param name="remove" />
<xsl:value-of select="$text" />
<xsl:if test="contains($text, $remove)">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="replace" select="$remove" />
<xsl:with-param name="by" select="''" />
</xsl:call-template>
<xsl:call-template name="remove-duplicate">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="remove" select="$remove" />
</xsl:call-template>
</xsl:if>
</xsl:template>
Calling the template:
<xsl:call-template name="remove-duplicate">
<xsl:with-param name="text" select="string(.)" />
<xsl:with-param name="remove" select="' ,'" />
</xsl:call-template>
The string-replace-all
was stolen from this question: XSLT string replace