[xsl] Calculating the size of a string

Subject: [xsl] Calculating the size of a string
From: Philip Vallone <philip.vallone@xxxxxxxxxxx>
Date: Wed, 15 Aug 2012 07:13:59 -0400
Hi List,

I have an xml input that will be processed into a FO file, via Saxon and
Apache's FOP (1.0). The resulting string will eventually be output to a
fo:table-cell. FOP does a decent job of hyphenating, however it is not
perfect. If I have a string input like this:

<pnr>PN-THIS.IS.A.LONG.PN12.23.56</pnr>

The output on PDF looks like this:

PN-
THIS.IS.A.LONG.PN12.23.56

the problems is that my cell is very small. I would like to have it look like
this:

PN-THIS.IS.A.
LONG.PN12.
23.56

I found a workaround, where if I include spaces in the string, I get better
results:

<pnr>PN-THIS.IS.A.LONG. PN12.23. 56</pnr>

However, this requires changing the input, which I don't want to do. I can not
use string-length because the size of the space can vary depending on the
characters used. For example, 'WWWWW', is bigger than 'iiiii' in actual size.
Both return a string-length of 5, but are not the same size. So, I've written
a java extension that will return the size of the Rectangle2D width. I have an
idea of where the 'line' break should be (140 the width of the framing
rectangle), but I am not sure how to translate the width into a function in
xslt to add the spaces.

Any ideas?

Thanks for the help

Phil

Current Thread