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

RE: text string handling or wrap

Subject: RE: text string handling or wrap
From: "Andrew Welch" <andrew@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 8 Jan 2002 15:48:47 -0000
td wrap text
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:  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) &gt; 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) &gt; 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) &gt; 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

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.