Placeholder

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"/>
</xsl:call-template>

 

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:call-template>
</xsl:template>
<xsl:template name="intersperse-with-zero-spaces">
    <xsl:param name="str"/>
    <xsl:variable name="spacechars">
        &#x9;&#xA;
        &#x2000;&#x2001;&#x2002;&#x2003;&#x2004;&#x2005;
        &#x2006;&#x2007;&#x2008;&#x2009;&#x200A;&#x200B;
    </xsl:variable>

    <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:text>&#x200B;</xsl:text>
        </xsl:if>

        <xsl:call-template name="intersperse-with-zero-spaces">
            <xsl:with-param name="str" select="substring($str, 2)"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>