How can I use the width attribute in my table template?
You need a template to process your style attribute which will extract its CSS properties. Here is something I've written a while ago for xslt-1, for xslt-2 this can be written much more elegantly:
<xsl:template name="process-style">
<xsl:param name="style"/>
<!-- get property name -->
<xsl:variable name="name" select="normalize-space(substring-before($style, ':'))"/>
<xsl:if test="$name">
<xsl:variable name="value-and-rest" select="normalize-space(substring-after($style, ':'))"/>
<xsl:variable name="value">
<xsl:choose>
<xsl:when test="contains($value-and-rest, ';')">
<xsl:value-of select="normalize-space(substring-before(
$value-and-rest, ';'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value-and-rest"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- process css properties -->
<xsl:choose>
<xsl:when test="$name = 'width'">
<xsl:attribute name="width">
<xsl:choose>
<xsl:when test="contains($value,'px')">
<!-- px to mm conversion -->
<xsl:value-of
select="number(normalize-space(substring-before($value,'px'))) * (2.54 div 72 * 10)"/>
<xsl:text>mm</xsl:text>
</xsl:when>
<!-- add additional conversions here if needed -->
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:when>
<xsl:when test="$name = 'background'">
<!-- add implementation for background processing -->
</xsl:when>
<!-- add addtional processing for other css properties here as needed
<xsl:when test="$name = 'color'"></xsl:when>
-->
<xsl:otherwise> </xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:variable name="rest" select="normalize-space(substring-after($style, ';'))"/>
<xsl:if test="$rest">
<xsl:call-template name="process-style">
<xsl:with-param name="style" select="$rest"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Add this to your stylesheet, and extend as needed to support other CSS properties that may appear in your style attributes.
Than call it like this:
<xsl:template match="table">
<fo:table>
<xsl:call-template name="process-style">
<xsl:with-param name="style" select="@style"/>
</xsl:call-template>
...
How can I use the cellpadding attribute in my td template?
In xsl-fo you cannot set cell-padding on the table so you would have to get it for each cell:
<xsl:template match="td">
<fo:table-cell>
<fo:block>
<!--
add padding to the block,
maybe overwrite with padding that might be stored with the td
-->
<xsl:attribute name="padding"><xsl:value-of select="ancestor::table/@cellpadding"/></xsl:attribute>
<xsl:apply-templates />
</fo:block>
</fo:table-cell>
</xsl:template>