| Subject: Re: [xsl] Column widths From: Joerg Heinicke <joerg.heinicke@xxxxxx> Date: Sun, 23 Jun 2002 11:40:49 +0200 | 
<xsl:template match="tr">
    <xsl:apply-templates select="td|th"/>
</xsl:template><xsl:template match="td|th">
  <xsl:variable name="x" select="position()"/>
  <fo:table-cell>
    <xsl:copy-of select="(ancestor::table/colgroup/col)[$x]/@width"/>
    <fo:block>
      <xsl:apply-templates/>
    </fo:block>
  </fo:table-cell>
</xsl:template><fo:table-cell width="30%" xmlns:fo="test"> <fo:block>A header</fo:block> </fo:table-cell> <fo:table-cell width="60%" xmlns:fo="test"> <fo:block>Some content here.</fo:block> </fo:table-cell> <fo:table-cell width="10%" xmlns:fo="test"> <fo:block>Some more here.</fo:block> </fo:table-cell>
Mike Brown wrote:
Brackets indicate predicates. Think of them as filters, providing everything to the left of them, for which everything inside them is true.
Got it.
Okay, here's a sample table:
<table> <colgroup> <col width="30%"/> </colgroup> <colgroup> <col width="60%"/> <col width="10%"/> </colgroup> <tbody> <tr> <th>A header</th> <td>Some content here.</td> <td>Some more here.</td> </tr> </tbody> </table>
For now, I assume there will always be equal amounts of table cells in a row as there are <col> elements. The result will look like this:
<fo:table> <fo:table-body> <fo:table-row> <fo:table-cell width="30%">...</fo:table-cell> <fo:table-cell width="60%">...</fo:table-cell> <fo:table-cell width="10%">...</fo:table-cell> </fo:table-row> </fo:table-body> </fo:table>
Here's how the <td> template looks like. The problem is in the long XPath expressions:
<xsl:template match="td">
<xsl:variable name="x" select="position()"/>
<fo:table-cell xsl:use-attribute-sets="table-padding">
...
<xsl:if test="ancestor::table//col[$x]/attribute::width">
<xsl:attribute name="width">
<xsl:value-of select="ancestor::table//col[$x]/attribute::width"/>
</xsl:attribute>
</xsl:if>
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:table-cell>
</xsl:template>
Gustaf
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] Column widths, Gustaf Liljegren | Thread | Re: [xsl] Column widths, Gustaf Liljegren | 
| Re: [xsl] String Manipulation, Steve Ball | Date | Re: [xsl] Column widths, Gustaf Liljegren | 
| Month |