Call us on : 1-305-260-6455

Customer Forum

Wrapping text within a table cell

Workbooks Support Posted: 2012-07-16 11:57

If you have a long word without spaces and put it in a table cell it might overflow the available space. The fix is to introduce "invisible spaces" between the characters of the value.  

Let's say you have a field called cf_customer_invoice_line_item_po_number. You would normally reference the field as shown below:


<xsl:value-of select="cf_customer_invoice_line_item_po_number"/>


Instead use this:


<xsl:call-template name="intersperse-with-zero-spaces">
    <xsl:with-param name="str" select="cf_customer_invoice_line_item_po_number"/>


Also, add the following XSL template to the end of your XSL template file:


<xsl:template match="text()">
    <xsl:call-template name="intersperse-with-zero-spaces">
        <xsl:with-param name="str" select="."/>
<xsl:template name="intersperse-with-zero-spaces">
    <xsl:param name="str"/>
    <xsl:variable name="spacechars">

    <xsl:if test="string-length($str) &gt; 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:call-template name="intersperse-with-zero-spaces">
            <xsl:with-param name="str" select="substring($str, 2)"/>