On Tue, 2004-05-25 at 16:08, Andreas L. Delmelle wrote:
> > -----Original Message-----
> > From: James Earl [mailto:[EMAIL PROTECTED]
> >
> 
> Hi,
> 
> <snip />
> > I'm just curious to know what people have found works best for them as
> > an alternative to achieving somewhat auto table layout?  I'm currently
> > trying to figure out what I should do.  I've just started learning XSL
> > as a result of beginning to use FOP to try to automatically create a
> > catalogue from data stored within a MySQL database.
> >
> > The only idea I've had so far, was to use the maximum column lengths as
> > returned from PHP's mysql_fetch_field() to somehow formulate a
> > proportional-column-width() value for the column-widths.
> >
> > As for the formula... I have no clue what that might be yet!  :)
> >
> 
> Hmm. proportional-column-width() could indeed do the trick here. Too bad
> XSLT doesn't have aggregate functions min() or max(), but this can be worked
> around rather easily.
> 
> Say your source XML looks like (--and you are actually using XML+XSLT to
> generate FO...)
> 
> <root>
>   <record>
>     <field index="1">Some piece of text</field>
>     <field index="2">A slightly longer portion of text</field>
>   </record>
>   <record>
>     <field index="1">Longer text in first field</field>
>     <field index="2">Shorter text in field two</field>
>   </record>
> </root>
> 
> Then, in XSLT, to construct a table offering the maximum field lengths
> mapped to column-widths, you could do something like (pseudo-code --well,
> almost... the code actually works):
> 
> <xsl:template match="root">
>   <fo:table table-layout="fixed" width="100%">
>     <!-- use the first row as basis; we only need the first row
>          to determine the number of columns (see CSS spec) -->
>     <xsl:apply-templates select="record[1]/field" mode="col-create" />
>     <fo:table-body>
>       <xsl:apply-templates select="record" mode="row-create" />
>     </fo:table-body>
>   </fo:table>
> </xsl:template>
> 
> <xsl:template match="field" mode="col-create">
>   <!-- create a variable to contain the maximum field-width ... -->
>   <xsl:variable name="vMax">
>     <!-- iterate over all fields with the same @index ... -->
>     <xsl:for-each select="/*/record/[EMAIL PROTECTED]()/@index]">
>       <!-- sort in descending order -->
>       <xsl:sort select="string-length()" order="descending" />
>       <!-- the first one in sorted order is the one we need -->
>       <xsl:if test="position()=1">
>         <xsl:value-of select="string-length()" />
>       </xsl:if>
>     </xsl:for-each>
>   </xsl:variable>
>   <!-- ... and use this maximum for prop-col-width -->
>   <fo:table-column column-number="[EMAIL PROTECTED]"
>                    column-width="{concat('proportional-column-width(',
>                      $vMax,')')}" />
> </xsl:template>
> 
> <xsl:template match="record" mode="row-create">
>   <fo:table-row>
>     <xsl:for-each select="field">
>     <fo:table-cell column-number="[EMAIL PROTECTED]">
>       <fo:block>
>         <xsl:value-of select="." />
>       </fo:block>
>     </fo:table-cell>
>   </fo:table-row>
> </xsl:template>
> 
> 
> Hope this gives you a clue...
> 
> 
> Greetz,
> 
> Andreas

Thanks for the example.

vMax is a string length in this example though, right?  Correct me if
I'm wrong, but I don't think proportional-column-width() will work with
a string length will it?

James




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to