[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] plain txt output tips

Subject: Re: [xsl] plain txt output tips
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 16 Apr 2002 16:10:41 +0100

> 1) What is the best way to force line breaks? Right
> now, I am using <xsl:text>&#xA;</xsl:text> to do it.


> 2) How can I limit the line length? I have run across
> several templates that break your lines at xx num of
> characters, but none of them a) consider breaking
> right in the middle of words nor b) how you handle
> breaking in a mixed content model, which is what I am
> working with.

If you're generating plain text then you can run all your templates
into the content of a variable, then you have the output as a string
which you can try to break.

Basically you want to tokenise on word boundaries (using a tokenise
extension, or one of Dimitre's functions, or a simple recusuive template
looking for substring-before(.,' '), then you want a recusive template
that runs over the list of tokens keeping a running total of the length
of the current line and adding a line break where needed.

That's the general case, in simple cases I've done something simpler:
if you know the words are basically rather short and you don't need to
get the "best possible" line breaking, then you can (assuming you are
aiming to break in column 80, for exampple
use substring($string,1,70)  to get most of the line then
substring-before(substring($string,71),' ') to get th erest of the final
word then recurse on the rest of the string which is
substring-after(substring($string,71),' ')


This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

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

Current Thread