Re: [xsl] XSLT Table defination Question

Subject: Re: [xsl] XSLT Table defination Question
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Fri, 21 Jun 2002 00:14:56 +0200
Use a recursive template:

<xsl:template match="element-with-text">
  <xsl:call-template name="chars">
    <xsl:with-param name="string" select="normalize-space()"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="chars">
  <xsl:param name="string" select="''"/>
  <xsl:param name="number-of-chars" select="20"/>
  <xsl:value-of select="substring($string, 1, 20)"/>-<br/>
  <xsl:if test="string-length($string) > 20">
    <xsl:call-template name="chars">
      <xsl:with-param name="string" select="substring($string, 21)"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

(untested)

Regards,

Joerg


Mehul Kishor Mehta wrote:
Hello,

I have question about XSLT. I have table with many columns. I want to restrict one of the table column no bigger that say 20 characters. But the problem is value I am putting in from XML file may have words which are longer than 20 characters and so table goes wide... !
e.g if the word is testverylongstringgreaterthantwentychar .
What happens is table goes wider.. and don't restrict it to 20 characters and rest show in next row..
I would like to have output something as follows..
testverylongstringic-
hgreaterthantwentych-
ar


Here is the sample of table defination within XSLT

<TABLE BORDER="true" CELLSPACING="1" CELLPADDING="4" WIDTH="98%">
    <TR>
        <TD WIDTH="20%" VALIGN="TOP" BGCOLOR="#66cccc" HEIGHT="10">
            <B><center>
                <FONT SIZE="2">
                    Attribute Name
                </FONT>
            </center></B>
        </TD>
</TABLE>

Do anyone know anyway I can do what I need ? I would be more than happy even if you point me to right place (if you know) for the question I have.

Thanks a lot for your help,
Mehul.


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


Current Thread