Subject: RE: [xsl] text string handling or wrap From: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 8 Jan 2002 15:48:47 -0000 |
ajay, Try: (I havent tested this with saxon3.2, let me know if it works) //put this template in between your <td> and </td> //remember to change $yourTextString (!) <xsl:call-template name="text_wrapper"> <xsl:with-param name="Text" select="$yourTextString"/> </xsl:call-template> //this will display the first 30 chars of $Text then pass the rest to wrapper_helper //if no string is left it will stop <xsl:template name="text_wrapper"> <xsl:param name="Text"/> <xsl:choose> <xsl:when test="string-length($Text)"> <xsl:value-of select="substring($Text,1,30)"/><br/> <xsl:call-template name="wrapper_helper"> <xsl:with-param name="Text" select="substring($Text,31)"/> </xsl:call-template> </xsl:when> <xsl:otherwise> no more string! </xsl:otherwise> </xsl:choose> </xsl:template> //this will also display 30 chars of the string, and pass the rest back to text_wrapper <xsl:template name="wrapper_helper"> <xsl:param name="Text"/> <xsl:value-of select="substring($Text,1,30)"/><br/> <xsl:call-template name="text_wrapper"> <xsl:with-param name="Text" select="substring($Text,31)"/> </xsl:call-template> </xsl:template> Cheers andrew === -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of ajay sinha Sent: Tuesday, January 08, 2002 2:39 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx; xsl-list-digest@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] text string handling or wrap Hi friends, I have a small problem. I have Text node with an string and when i am displaying it in tablecell i.e. <td> on client.The problem is,If any word increases more then 30 letters it dosnt wrap the text and table get deformed.to tackle it I used an template which is as follows <xsl:template name="textwrap"> <xsl:param name="Text"/> <xsl:value-of select="substring($Text, 1, 30)"/> <br></br> <xsl:variable name="rest" select="substring($Text, 31)" /> <xsl:if test="string-length($rest) > 30"> <xsl:call-template name="textwrap"> <xsl:with-param name="Text" select="$rest" /> </xsl:call-template> </xsl:if> </xsl:template> But As I am using old verson of saxon(3.2)It dosnt support tail recursion.then I tried following <xsl:template name="textwrap"> <xsl:param name="Text"/> <xsl:variable name="linelen" select="30"/> <xsl:choose> <xsl:when test="string-length($Text) > 30"> <xsl:value-of select="substring(Text, 1, 30)"/> <br/> <xsl:call-template name="textwrap"> <xsl:with-param name="Text" select="substring($Text, 31)"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$Text"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="textwrapzz"> <xsl:param name="Text"/> <xsl:choose> <xsl:when test="$Text!=''"> <xsl:choose> <xsl:when test="string-length($Text) > 30"> <xsl:value-of select="substring(Text, 1, 30)"/> <br></br> <xsl:variable name="rest" select="substring(Text, 31)"/> <xsl:call-template name="textwrap"> <xsl:with-param name="Text" select="$rest"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$Text"/> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="$Text"/> </xsl:otherwise> </xsl:choose> </xsl:template> But This code is getting too long as string can be upto three hundred charector long. So please any body can tell me how i can find any word longer then 30 charectors in a text string and then break it in thirty letters words each without using recursion. I will be really greatfull if some body provides me code example. Thanks in anticipation. your frienddly ajrapa _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] text string handling or wrap, ajay sinha | Thread | [xsl] Whitespace in XSLT: Everythin, Joshua Allen |
[xsl] XPath 2.0, Miloslav Nic | Date | Re: default template (was:RE: [xsl], David Carlisle |
Month |