Discussion:
dynamic fo:table-column width?
Luke Jones
2007-05-30 14:30:18 UTC
Permalink
XSL Experts,

I'm trying to create a dynamic table where the columns are based off of
the length of the longest string that the cell will hold. An example
will probably be the best way to explain.

Say I have the following xml document:

<tbl>
<r>
<c1>73-123</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
<r>
<c1>73-1,453 and 73-1,454</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
</tbl>

< para and chapter information .... blah blah blah />

<tbl>
<r>
<c1>74-056</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
<r>
<c1>74-324</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
</tbl>

<para and chapter information .... blah blah blah />


Currently I have fixed column-widths, so my tables look like:

73-123 Chapter XX-XXX for legal docs
73-1,453 and 73-1,454 Chapter XX-XXX for legal docs

para and chapter information...

74-056 Chapter XX-XXX for legal docs
74-324 Chapter XX-XXX for legal docs

para and chapter information...

However, I would like the column widths to be based off of the longest
string within the c1 column plus 2 spaces. This would make the tables
look like:

73-123 Chapter XX-XXX for legal docs
73-1,453 and 73-1,454 Chapter XX-XXX for legal docs

para and chapter information...

74-056 Chapter XX-XXX for legal docs
74-324 Chapter XX-XXX for legal docs

para and chapter information...

So the content of the cells effects the size of the columns. Is what
I'm wanting to do possible? I've done some searching and haven't found
anything that addresses this problem specifically. Any ideas or input
is greatly appreciated.

Thanks,
Luke


--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Eliot Kimber
2007-05-30 14:41:59 UTC
Permalink
Post by Luke Jones
XSL Experts,
I'm trying to create a dynamic table where the columns are based off of
the length of the longest string that the cell will hold. An example
will probably be the best way to explain.
One way to do it might be to wrap the content of the column you want to
be dynamic within fo:inline with a keep-together.within-line="always".
This should disallow breaking of the line. By then using automatic table
layout, you should get what you want, at least for that line.

Another solution is to create an XSLT extension function that can
estimate the rendered length of the content and then use that estimate
to set the column width. I've done this in Java using the standard Java
graphics API. It requires that you know the current font and font size
(which presumably you can know if you're generating the output), but the
programming was relatively easy, if memory serves (I don't have the code
to hand).

Otherwise there is direct way to do what you want.

Cheers,

Eliot
--
W. Eliot Kimber
Professional Services
Innodata Isogen
8500 N. Mopac, Suite 402
Austin, TX 78759
(214) 954-5198

***@innodata-isogen.com
www.innodata-isogen.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-***@lists.mulberrytech.com>
--~--
Luke Jones
2007-05-30 14:51:39 UTC
Permalink
Post by Eliot Kimber
One way to do it might be to wrap the content of the column you want to
be dynamic within fo:inline with a keep-together.within-line="always".
This should disallow breaking of the line. By then using automatic table
layout, you should get what you want, at least for that line.
Another solution is to create an XSLT extension function that can
estimate the rendered length of the content and then use that estimate
to set the column width. I've done this in Java using the standard Java
graphics API. It requires that you know the current font and font size
(which presumably you can know if you're generating the output), but the
programming was relatively easy, if memory serves (I don't have the code
to hand).
Otherwise there is direct way to do what you want.
Thanks for the input. Unfortunately I'm using fop to render the pdf and
the auto table-layout isn't currently supported. I'll give the
extension function a go. If any other ideas pop up, please let me
know!

Thanks,
Luke


--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Jay Bryant
2007-05-30 14:52:04 UTC
Permalink
Hi, Luke,

That's a question I've answered before on a different mailing list. It took
me a bit to find my previous message (if I hadn't known I'd written it, I
never would have found it).

Here's a link to that old answer:
http://marc.info/?l=fop-user&m=112732887606348&w=2

It works, but it relies on a longish bit of easy-to-misunderstand code, so
it may not be a worthwhile solution. Still, it may give you an idea for your
own, better solution.

HTH

Jay Bryant
Bryant Communication Services



----- Original Message -----
From: "Luke Jones" <***@leg.ne.gov>
To: <xsl-***@lists.mulberrytech.com>
Sent: Wednesday, May 30, 2007 9:30 AM
Subject: [xsl] dynamic fo:table-column width?
Post by Luke Jones
XSL Experts,
I'm trying to create a dynamic table where the columns are based off of
the length of the longest string that the cell will hold. An example
will probably be the best way to explain.
<tbl>
<r>
<c1>73-123</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
<r>
<c1>73-1,453 and 73-1,454</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
</tbl>
< para and chapter information .... blah blah blah />
<tbl>
<r>
<c1>74-056</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
<r>
<c1>74-324</c1>
<c2> Chapter XX-XXX for legal docs</c2>
</r>
</tbl>
<para and chapter information .... blah blah blah />
73-123 Chapter XX-XXX for legal docs
73-1,453 and 73-1,454 Chapter XX-XXX for legal docs
para and chapter information...
74-056 Chapter XX-XXX for legal docs
74-324 Chapter XX-XXX for legal docs
para and chapter information...
However, I would like the column widths to be based off of the longest
string within the c1 column plus 2 spaces. This would make the tables
73-123 Chapter XX-XXX for legal docs
73-1,453 and 73-1,454 Chapter XX-XXX for legal docs
para and chapter information...
74-056 Chapter XX-XXX for legal docs
74-324 Chapter XX-XXX for legal docs
para and chapter information...
So the content of the cells effects the size of the columns. Is what
I'm wanting to do possible? I've done some searching and haven't found
anything that addresses this problem specifically. Any ideas or input
is greatly appreciated.
Thanks,
Luke
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
--~--
--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Luke Jones
2007-05-30 16:56:05 UTC
Permalink
Post by Jay Bryant
Hi, Luke,
That's a question I've answered before on a different mailing list. It took
me a bit to find my previous message (if I hadn't known I'd written it, I
never would have found it).
http://marc.info/?l=fop-user&m=112732887606348&w=2
It works, but it relies on a longish bit of easy-to-misunderstand code, so
it may not be a worthwhile solution. Still, it may give you an idea for your
own, better solution.
Thanks! In your code you used {}'s around variables and attributes
within the column-width. I did not realize you could do this! (which is
probably xsl 101 :] ) I ended up writing a function to insert an
attribute into the tag, and then used column-width = "{@name}in" for the
'dynamic' column size.

Thanks for all the help,
Luke

--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--

Loading...