xsl-list
[Top] [All Lists]

RE: [xsl] Center string

2009-06-11 07:59:28

I think you need to move from

(0) a set of examples, to

(1) a requirement statement, to

(2) an algorithm, to

(3) an implementation in XSLT code.

Perhaps (1) is something like: generate the output in as few lines as
possible given the maximum line length, and then divide the words between
lines so as to minimize the maximum variation between actual line length and
average line length.

Perhaps (2) is something like:

  (a) compute the minimum number of lines by first trying to pack the words
as densely as possible.

  (b) compute the average line length by dividing the total length by the
minimum number of lines

  (c) flow the words into lines breaking each line at the closest possible
point to the average line length.

If that's OK, then step (3) is relatively straightforward so long as you are
comfortable with recursion, though like most such things it's likely to be
much easier in XSLT 2.0 than in 1.0.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

-----Original Message-----
From: djidjoenator(_at_)gmail(_dot_)com 
[mailto:djidjoenator(_at_)gmail(_dot_)com] 
On Behalf Of Frédéric Schwebel
Sent: 11 June 2009 12:42
To: xsl-list
Subject: [xsl] Center string

Hi folks,

Just curious if it has already been done : I need to center a 
string with a max line length. The words must be uncut and 
balanced between lines.

Example :
----------------
¨mathématiques niveau lycée: série
                   '1
----------------- is incorrect

           ¨mathématiques
          niveau lycée: série
                   '1
----------------- is incorrect

 ¨mathématiques niveau
       lycée: série '1
----------------- is correct

Centering the lines is not a problem. The most difficult part 
is to balance words with line-length. Did somebody already do 
this with XSL ?
Thanks for any help,
Frederic

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>