You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Alastair Growcott <al...@pipstechnology.co.uk> on 2002/07/18 15:42:28 UTC

Dynamic table columns

Hiya, all.

I have an XSL table that describes the attributes of none or more
objects. Because there are so many attributes, I want the attributes to
be the row headers with one column per object.

What XSL do I need to convert this to a FOP table of the same sort? I
can do some re-structuring of the XSL data if absolutely necessary.

E.g. my XSL file contains;

<object>
<attr1>hello</attr1>
<attr2>there</attr2>
<attr3>all</attr3>
<attr4>you</attr4>
<attr5>nice</attr5>
<attr6>helpful</attr6>
<attr7>people</attr7>
</object>
<object>
<attr1>I</attr1>
<attr2>could</attr2>
<attr3>really</attr3>
<attr4>really</attr4>
<attr5>use</attr5>
<attr6>some</attr6>
<attr7>help</attr7>
</object>

And I need this displayed as;

Attr1		hello		I
Attr2		there		could
Attr3		all		really
Attr4		you		really
Attr5		nice		use
Attr6		helpful	some
Attr7		people	help

Thanks very much in advance.

Alastair.





Re: Dynamic table columns

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Alastair Growcott wrote:
> I have an XSL table that describes the attributes of none or more
> objects. Because there are so many attributes, I want the attributes to
> be the row headers with one column per object.

Questions regarding XSLT are best asked on the XSL list
(see below).

For you problem, try:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
   xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <xsl:template match="objects">
     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
       <fo:layout-master-set>
         <fo:simple-page-master master-name="page"
           page-width="20cm" page-height="30cm">
           <fo:region-body/>
         </fo:simple-page-master>
       </fo:layout-master-set>
       <fo:page-sequence master-reference="page">
         <fo:flow flow-name="xsl-region-body">
           <fo:table table-layout="fixed">
             <fo:table-column column-width="35mm"/>
             <fo:table-column column-width="35mm"/>
             <fo:table-column column-width="35mm"/>
             <fo:table-body>	
               <xsl:variable name="objects" select="object"/>
               <xsl:for-each select="object[1]/*">
                 <xsl:variable name="name" select="name()"/>
                 <xsl:variable name="index" select="position()"/>
                 <fo:table-row>
                   <fo:table-cell>
                     <fo:block>
                       <xsl:value-of select="$name"/>
                     </fo:block>
                   </fo:table-cell>
                   <xsl:for-each select="$objects">
                     <fo:table-cell>
                       <fo:block>
                         <xsl:value-of select="*[$index]"/>
                       </fo:block>
                     </fo:table-cell>
                   </xsl:for-each>
                 </fo:table-row>
               </xsl:for-each>
             </fo:table-body>
           </fo:table>
         </fo:flow>
       </fo:page-sequence>
     </fo:root>
   </xsl:template>
</xsl:stylesheet>

on

<?xml version="1.0"?>
<objects>
   <object>
     <attr1>hello</attr1>
     <attr2>there</attr2>
     <attr3>all</attr3>
     <attr4>you</attr4>
     <attr5>nice</attr5>
     <attr6>helpful</attr6>
     <attr7>people</attr7>
   </object>
   <object>
     <attr1>I</attr1>
     <attr2>could</attr2>
     <attr3>really</attr3>
     <attr4>really</attr4>
     <attr5>use</attr5>
     <attr6>some</attr6>
     <attr7>help</attr7>
   </object>
</objects>


The XSLT is very brittle (think about it). There are more
general solutions available in the archives of the XSL
list
   http://www.mulberrytech.com/xsl/xsl-list/

J.Pietschmann