Table style templates

View: New views
4 Messages — Rating Filter:   Alert me  

Table style templates

by dahepe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm almost new to XSL and XSL-FO and I'm wondering if there is some possibility to define style templates for tables.

Currently I'm doing somthing like this:

...
<fo:table table-layout="fixed" width="100%" border-style="solid">

  <fo:table-column column-width="proportional-column-width(100)"/>
  <fo:table-column column-width="proportional-column-width(18)"/>
  <fo:table-column column-width="proportional-column-width(16)"/>
  <fo:table-column column-width="proportional-column-width(16)"/>
  <fo:table-column column-width="proportional-column-width(25)"/>
 
  <fo:table-header border-style="solid" background-color="lightgray">
    <fo:table-cell border-style="solid" padding="2pt">
      <fo:block font-weight="bold">Documentname</fo:block>
    </fo:table-cell>
    <fo:table-cell border-style="solid" padding="2pt">
      <fo:block font-weight="bold">Version</fo:block>
    </fo:table-cell>
    <fo:table-cell border-style="solid" padding="2pt">
      <fo:block font-weight="bold">Format</fo:block>
    </fo:table-cell>
    <fo:table-cell border-style="solid" padding="2pt">
      <fo:block font-weight="bold">Status</fo:block>
    </fo:table-cell>
    <fo:table-cell border-style="solid" padding="2pt">
      <fo:block font-weight="bold">Sector</fo:block>
    </fo:table-cell>
  </fo:table-header>
 
  <fo:table-body>
    <xsl:apply-templates />
  </fo:table-body>
</fo:table>

...
<xsl:template match="attachment">
  <fo:table-row>
    <fo:table-cell padding-before="1pt" padding-after="1pt" padding-start="2pt" padding-end="2pt"
        border-style="solid">
      <fo:block><xsl:value-of select="name" /></fo:block>
    </fo:table-cell>
    <fo:table-cell padding-before="1pt" padding-after="1pt" padding-start="2pt" padding-end="2pt"
        border-style="solid">
      <fo:block><xsl:value-of select="version" /></fo:block>
    </fo:table-cell>
    <fo:table-cell padding-before="1pt" padding-after="1pt" padding-start="2pt" padding-end="2pt"
        border-style="solid">
      <fo:block><xsl:value-of select="format" /></fo:block>
    </fo:table-cell>
    <fo:table-cell padding-before="1pt" padding-after="1pt" padding-start="2pt" padding-end="2pt"
        border-style="solid">
      <fo:block><xsl:value-of select="status" /></fo:block>
    </fo:table-cell>
    <fo:table-cell padding-before="1pt" padding-after="1pt" padding-start="2pt" padding-end="2pt"
        border-style="solid">
      <fo:block><xsl:value-of select="sector" /></fo:block>
    </fo:table-cell>
  </fo:table-row>
</xsl:template>

My problem is that for each data cell the style has to be defined explicitly. That is there are multiple padding and border-style tags that are just redundant. And these format related things are furthermore part of the section that handles the actual data, which is not that nice from my point of view.

What I'm thinking of is to define the actual style of the whole table (i.e. padding, borders, heading style, etc.) in some kind of reference design that can be referred on in the stylesheet. Similar to CSS ore even the page master definition in XSL-FO one should be able to say

<fo:table table-style-reference="MyNiceLookingTable">
  <!-- the data oriented stuff goes here -->
</fo:table>

Thus one is not bordered with the table design everytime when adding a new row or even when adding a second table that should look the same...

Is something like this possible using XSL-FO?

Best regards,
Daniel.

Re: Table style templates

by David Carlisle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



The model for XSL FO is that (more or less) everything is expanded out
in the FO file, but the program that you use to create that file
(usually XSLT) can of course use the features of that language to
organise the generation.

here for example it looks like you could use a named template, something
like

<xsl:template name="cell">
  <xsl:param name="body"/>
      <fo:table-cell padding-before="1pt" padding-after="1pt"
padding-start="2pt" padding-end="2pt"
        border-style="solid">
      <fo:block><xsl:value-of select="$body/></fo:block>
    </fo:table-cell>
</xsl:template>

Then

<xsl:call-template>
  <xsl:param name="body" select="format"/>
</xsl:call-template>
<xsl:call-template>
  <xsl:param name="body" select="sector"/>
</xsl:call-template>

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________


Re: Table style templates

by Jeremias Maerki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


In addition to that, the xsl:attribute-set and xsl:use-attribute-sets
pair (both XSLT features) served me well in the past. I often create a
separate "styles" stylesheet with only attribute sets which I then
import in the other stylesheets to separate large parts of the FO
styling from the actual transformation logic.

On 13.11.2008 10:49:14 David Carlisle wrote:

>
>
> The model for XSL FO is that (more or less) everything is expanded out
> in the FO file, but the program that you use to create that file
> (usually XSLT) can of course use the features of that language to
> organise the generation.
>
> here for example it looks like you could use a named template, something
> like
>
> <xsl:template name="cell">
>   <xsl:param name="body"/>
>       <fo:table-cell padding-before="1pt" padding-after="1pt"
> padding-start="2pt" padding-end="2pt"
>         border-style="solid">
>       <fo:block><xsl:value-of select="$body/></fo:block>
>     </fo:table-cell>
> </xsl:template>
>
> Then
>
> <xsl:call-template>
>   <xsl:param name="body" select="format"/>
> </xsl:call-template>
> <xsl:call-template>
>   <xsl:param name="body" select="sector"/>
> </xsl:call-template>
>
> David



HTH,
Jeremias Märki
_________________________________________________________
Jeremias Märki, Software-Development and Consulting
Contact Information: http://www.jeremias-maerki.ch/contact.html
Blog: http://www.jeremias-maerki.ch/blog/



Re: Table style templates

by dahepe :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for your replies!!

Both the named template and the attribute-set suggestion helped a lot.

I think I'll stay with the attribute sets as it seems more intuitive for me. That is only the formatting stuff (padding, font, alignment, etc.) is referenced and the actual structure (table cells and rows) remains.

For the curious looking for an example for how to use an attribute set (I had a little problem with this, too) here is what my table heading declaration now looks like:
...
<fo:table-header background-color="lightgray">
  <fo:table-row>
    <fo:table-cell xsl:use-attribute-sets="header-cell-attrs">
      <fo:block>Documentname</fo:block>
    </fo:table-cell>
    <fo:table-cell xsl:use-attribute-sets="header-cell-attrs">
      <fo:block>Version</fo:block>
    </fo:table-cell>
    <fo:table-cell xsl:use-attribute-sets="header-cell-attrs">
      <fo:block>Format</fo:block>
    </fo:table-cell>
    <fo:table-cell xsl:use-attribute-sets="header-cell-attrs">
      <fo:block>Status</fo:block>
    </fo:table-cell>
    <fo:table-cell xsl:use-attribute-sets="header-cell-attrs">
      <fo:block>Sector</fo:block>
    </fo:table-cell>
  </fo:table-row>
</fo:table-header>
...

<xsl:attribute-set name="header-cell-attrs">
  <xsl:attribute name="border-style">solid</xsl:attribute>
  <xsl:attribute name="font-weight">bold</xsl:attribute>
  <xsl:attribute name="padding">2pt</xsl:attribute>
</xsl:attribute-set>
...

Thanks a lot,
Daniel.

Jeremias Maerki-2 wrote:
In addition to that, the xsl:attribute-set and xsl:use-attribute-sets
pair (both XSLT features) served me well in the past. I often create a
separate "styles" stylesheet with only attribute sets which I then
import in the other stylesheets to separate large parts of the FO
styling from the actual transformation logic.

On 13.11.2008 10:49:14 David Carlisle wrote:
>
>
> The model for XSL FO is that (more or less) everything is expanded out
> in the FO file, but the program that you use to create that file
> (usually XSLT) can of course use the features of that language to
> organise the generation.
>
> here for example it looks like you could use a named template, something
> like
>
> <xsl:template name="cell">
>   <xsl:param name="body"/>
>       <fo:table-cell padding-before="1pt" padding-after="1pt"
> padding-start="2pt" padding-end="2pt"
>         border-style="solid">
>       <fo:block><xsl:value-of select="$body/></fo:block>
>     </fo:table-cell>
> </xsl:template>
>
> Then
>
> <xsl:call-template>
>   <xsl:param name="body" select="format"/>
> </xsl:call-template>
> <xsl:call-template>
>   <xsl:param name="body" select="sector"/>
> </xsl:call-template>
>
> David



HTH,
Jeremias Märki
_________________________________________________________
Jeremias Märki, Software-Development and Consulting
Contact Information: http://www.jeremias-maerki.ch/contact.html
Blog: http://www.jeremias-maerki.ch/blog/