`The requirement is to print the data in tabular form, whenever there is a long string which is greater than column width, it is coming out of the column and we are facing text overlapping issue. We have two types of data coming from our application UI.
- Text field data - we have successfully implemented word break for this kind of data.
- RTE(Rich Text editor) data - we tried to implement the same approch but the data is either printing multiple times or not printing at all, also affecting the stylings of the text. The root cause is RTE data coming with html paragraph, span and styling tags like strong, u tags.
This below piece of code is using to break the word based on column width. But this is not working for the data which are coming with the html tags.
<xsl:template name="intersperse-with-zero-spaces">
<xsl:param name="str"/>
<xsl:param name="column-width"/>
<xsl:if test="string-length($str) > 0">
<xsl:variable name="s1" select="substring-before($str, ' ')"/>
<xsl:variable name="s2" select="substring-after($str, ' ')"/>
<xsl:variable name="chars-per-inch" select="number($column-width*6)" />
<xsl:if test="$s1 != '' and string-length($s1) < $chars-per-inch">
<xsl:value-of select="$s1" />
</xsl:if>
<xsl:if test="$s1 != '' and string-length($s1) >= $chars-per-inch">
<xsl:call-template name="intersperse-with-zero-spaces-str">
<xsl:with-param name="str" select="$s1"/>
</xsl:call-template>
</xsl:if>
<!-- Adding space after every word -->
<xsl:text> </xsl:text>
<xsl:call-template name="intersperse-with-zero-spaces">
<xsl:with-param name="str" select="$s2"/>
<xsl:with-param name="column-width" select="$column-width"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="intersperse-with-zero-spaces-str">
<xsl:param name="str"/>
<xsl:variable name="spacechars">	
           ​</xsl:variable>
<xsl:if test="string-length($str) > 0">
<xsl:variable name="c1" select="substring($str, 1, 1)" />
<xsl:variable name="c2" select="substring($str, 2, 1)" />
<xsl:value-of select="$c1"/>
<xsl:if test="$c2 != '' and not(contains($spacechars, $c1) or contains($spacechars, $c2))">
<xsl:text>​</xsl:text>
</xsl:if>
<xsl:call-template name="intersperse-with-zero-spaces-str">
<xsl:with-param name="str" select="substring($str, 2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
If your element() contains html-markup, I suppose you need to call that template from every text-node() inside your element () like this: