[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: word wrap in a text string

Subject: RE: word wrap in a text string
From: "Andrew Welch" <awelch@xxxxxxxxxxxxxxx>
Date: Thu, 7 Mar 2002 09:10:57 -0000
wrap text in td ie

>I have to do wrap text in a td i.e. in a node, which contains text string I
>have to find if any Word has more then 30 characters then insert a br tag
after 30 char in that
>word and so on....

Hi,

This should do it without recursion:


//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

===

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.325 / Virus Database: 182 - Release Date: 2/19/02



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.