Re: [xsl] xsl-fo? center external-graphic and align start side of caption with start side of external-graphic

Subject: Re: [xsl] xsl-fo? center external-graphic and align start side of caption with start side of external-graphic
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 08 Dec 2009 15:14:52 -0500
At 2009-12-08 11:13 -0800, Jack Bates wrote:
I want some XSL-FO external-graphics to appear centered on the page,
with captions underneath

If the external-graphic is wider than the caption, then I want the left
or start side of the caption to be aligned with the left or start side
of the external-graphic

If the caption is wider than the external-graphic, then I want the
caption to appear centered on the page (I want the external-graphic also
centered on the page, as before)

There are no pre-built semantics for such a choice as you have expressed. Remember there is no feedback loop from the formatter to your transformation, so you have to find a way of expressing any contingencies by using the already-available semantics in the formatting language.

And measuring formatted items, or comparing the lengths of formatted items, is not available for any kind of comparison.

To achieve this I wrapped both the external-graphic and the caption in
blocks, then wrapped both those blocks in one block, and set
text-align="center" on that block's container. Then I set
text-align="start" on the caption's block. I hoped this would have the
effect of centering the block containing both external-graphic and
caption, and aligning the caption against the start side of that block.

Nope ... because blocks are as wide as their closest ancestral reference area.

I'm thinking you will have to know the width of the graphic explicitly in advance, and then you can create a container of that width and flow your caption into that container.

Wait ... have you tried centring a border-less table with auto-width? Put both blocks into a single table cell in a single row. The XSL-FO default for table-width is an automatic calculation made by the formatter, so hopefully it will be as tight as either the graphic or the caption but no bigger. Then, the way one centres a table with XSL-FO is to put it in a table-and-caption and use text-align= (which is the standard way to do inline-progression-direction centring) on the table-and-caption to align the child table. You typically then need another text-align= on the table to reset the alignment for the table cells (unless you want them centred as well).

That might get you closer to what you want.

I hope this helps.

. . . . . . . . . . . Ken

XSLT/XQuery/XPath training after 2010-03-15/19
Vote for your XML training:
Crane Softwrights Ltd.
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:
Video overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread