« Follow Up on the Abuse Report Draft Browser Differences in window.opener Behavior »
How To Wrap Text in a Table Cell with XSLT
Posted May 5, 2005 – 12:06 pm by Yakov Shafranovich in ProgrammingAs a followup to yesterday’s post, here is how I am wrapping text via XSLT as opposed to CSS and JavaScript. The reason why I am prefering to do this server side via XSLT as opposed to JavaScript client-side is because if I will be doing client-side JavaScripts, I would have to escape the stuff during the HTML generation anyway in XSLT server-side. So in the same processing power I might as well wrap it instead. Of course you can also do it via some fancy JavaScript client side by going through the entire table and chopping up the text in each row, but that would make things look rather interesting to the user (tables automatically re-arranging themselves).
Anyway, here is a simple recursive template based on the code posted by Andrew Welch:
<xsl:template name="text_wrapper">
<xsl:param name="text"/>
<xsl:param name="width" select="20"/>
<xsl:if test="string-length($text)">
<xsl:value-of select="substring($text, 1, $width)"/><br/>
<xsl:call-template name="text_wrapper">
<xsl:with-param name="text"
select="substring($text, $width + 1)"/>
<xsl:with-param name="width" select="$width"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
To use it, call it as follows:
<xsl:call-template name="text_wrapper"> <xsl:with-param name="text" select="sometext"/> <xsl:with-param name="width" select="20"/> </xsl:call-template>Digg This Share This Post
Permalink | Trackback URL | This post has 912 Views














