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

Re: how to make data fit in a table cell in xsl-fo?

Subject: Re: how to make data fit in a table cell in xsl-fo?
From: Joerg Pietschmann <joerg.pietschmann@xxxxxx>
Date: Thu, 17 Jan 2002 13:09:19 +0100
fo block hyphenation
yan bai <bytj@xxxxxxxxx> wrote:
> The table has 7 columns.  One of the columns may
> contain a string like
> "ABCD_XXX_YYY_D1_ZZZ_DDD_DD0_DA0".  This column will
> expand into the next column "col_2" and make the data
> in the "col_2" column ineligible.

That's quite obvious. What i'd like to know is what you
want to have instead.
I'll use the following FO snippet as example:
    <fo:table-column column-width="20mm"/>
    <fo:table-column column-width="20mm"/>

For solutions at the FO-level, you can try hyphenation:
  <fo:block hyphenate="true" language="en">ABCD_XXX_YYY_D1_ZZZ_DDD_DD0_DA0</fo:block>
This works somehow. FOP (0.20.2) will spout some errors ([ERROR]: >)
which indicate repeated area overflow, you can ignore them. You might
want to customize the hyphenation further, look at the 
for possibilities. Of course, hyphenation works best if the long words
are really words. If they are artificial constructs as your example
suggests (sort of product ids or something similar), hyphenation
might not be what you want.

The other solution, having long strings clipped at the cell boundary,
apparently is not possible with FOP as it requires not yet implemented

There are also some possible solutions at the XSLT level, in case you
generate the FO this way.
- You could insert a zero width space (&#x200b;) into long strings,
 for example by replacing "_" by "_&#x200b;". The FO processor is able
 to wrap the string at the zero width spaces if needed, and the spaces
 go unnoticed where no wrap is necessary. This gives you some control
 where the string can be wrapped but will of course fail if long
 substrings without an inserted zero width space remain. Unfortunately,
 this sort of replacement is not all that easy to do in XSLT, look at
 or the archives of this list for some hints. You might want to combine
 this with a tokenizer in order to process only long words, here
 might get you started (use spaces instead of commas, of course).
 Alternatives are to insert a zero width space after each character, or
 after each N characters, where N characters can be expected to fit
 into the cell.
- You could simply cut off long strings after N characters. Use a
 tokenizer to get the words in your text and use substring() on them.
- Format the text yourself in order to ensure lines are no longer than
 N characters, either clipping or wrapping long strings in the process.
 You'll have to build a recursive template solution along the lines
 of the string replace mentioned above. I'm sure the list archive
 already contains code which could be reused.
Be aware that the possible solutions which include "N character" may
result in somewhat unpleasant appearance if you use a proportional
font, as N has to be a preset constant.

If you are after calculating column withs in order to fit the data
into the cells, well, this can't currently be done in FO. For a
solution at the XSLT level, you may use a tokenizer as mentioned
above to get the words in the texts and try to derive the necessary
column width from the string length of the words. In case you use
proportional fonts you'll run into the same difficulties as in some
of the possibilities mentioned above because you'll need font metrics
for exact calculations, and there is no easy way in XSLT to retrieve

Now: What do you actually mean by "fit data into a table cell"?


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

Current Thread


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.
First Name
Last Name
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.