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

RE: Center string

Subject: RE: Center string
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 11 Jun 2009 12:58:51 +0100
RE:  Center string
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@xxxxxxxxx [mailto:djidjoenator@xxxxxxxxx]
> On Behalf Of Fridiric Schwebel
> Sent: 11 June 2009 12:42
> To: xsl-list
> Subject:  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 :
> ----------------
> (mathimatiques niveau lycie: sirie
>                    '1
> ----------------- is incorrect
>
>            (mathimatiques
>           niveau lycie: sirie
>                    '1
> ----------------- is incorrect
>
>  (mathimatiques niveau
>        lycie: sirie '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

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.