Last active
January 17, 2016 16:01
-
-
Save yakovsh/5d01cc174110c09eb621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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: | |
https://web.archive.org/web/20070116081723/http://www.xslt.com/html/xsl-list/2002-03/msg00334.html | |
--> | |
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment