title: XSL - calculating table widths
body: <p>I am having an issue on trying to get the width for each td, I am currently getting out a blank value inside my column-width, how do I get the value of each td.</p>
  
  <pre><code> &lt;xsl:template match="table"&gt;
      &lt;fo:table table-layout="fixed"&gt;
      &lt;xsl:call-template name="tokenize-style"/&gt;
        &lt;!-- Calculate the table cols... --&gt;
        &lt;xsl:for-each select="tbody/tr[1]/td"&gt;
          &lt;fo:table-column&gt;  
            &lt;xsl:attribute name="column-width"&gt;
  &lt;xsl:value-of select="@width"&gt;&lt;/xsl:value-of&gt;
  
            &lt;/xsl:attribute&gt;
          &lt;/fo:table-column&gt;
        &lt;/xsl:for-each&gt;
        &lt;xsl:apply-templates select="*|text()"/&gt;
      &lt;/fo:table&gt;
    &lt;/xsl:template&gt;
    &lt;xsl:template match="tbody"&gt;
      &lt;fo:table-body&gt;
        &lt;xsl:apply-templates select="*|text()"/&gt;
      &lt;/fo:table-body&gt;
    &lt;/xsl:template&gt;
  </code></pre>
  
  <p>Based on the HTML -></p>
  
  <pre><code>&lt;table class="te-tablerenderer" style="width: 170mm; text-align: left;"&gt;
              &lt;tbody style="text-align: left;"&gt;
                 &lt;tr class="" style="text-align: left;"&gt;
                    &lt;td style="width: 141px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); "&gt; &lt;/td&gt;
                    &lt;td style="width: 143px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); "&gt;          
                       &lt;b&gt;Postcode:&lt;/b&gt;        
                    &lt;/td&gt;       
                    &lt;td class="GENTICS_Table_Cell_active"
                        style="width: 325px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); "&gt;          
                       djnds fnjksdnf      
                    &lt;/td&gt;        
                    &lt;td style="width: 33px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); "&gt;         &lt;/td&gt;    
                 &lt;/tr&gt;
              &lt;/tbody&gt;
           &lt;/table&gt;
  </code></pre>
  
  <p>Note: This is the template I call when I want to get all my styles for an element:</p>
  
  <pre><code>  &lt;xsl:template name="tokenize-style"&gt;
      &lt;xsl:param name="pString" select="string(@style)"/&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test="not($pString)"/&gt;
        &lt;xsl:when test="contains($pString,';')"&gt;
          &lt;xsl:call-template name="tokenize-style"&gt;
            &lt;xsl:with-param name="pString"
                 select="substring-before($pString,';')"/&gt;
          &lt;/xsl:call-template&gt;
          &lt;xsl:call-template name="tokenize-style"&gt;
            &lt;xsl:with-param name="pString"
                 select="substring-after($pString,';')"/&gt;
          &lt;/xsl:call-template&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:otherwise&gt;
          &lt;xsl:attribute name="{normalize-space(substring-before($pString,':'))}"&gt;
            &lt;xsl:value-of select="normalize-space(substring-after($pString,':'))"/&gt;
          &lt;/xsl:attribute&gt;
        &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:template&gt;
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>&lt;fo:table table-layout="fixed" width="170mm" text-align="left"&gt;
                    &lt;fo:table-column column-width=""/&gt;
                    &lt;fo:table-column column-width=""/&gt;
                    &lt;fo:table-column column-width=""/&gt;
                    &lt;fo:table-column column-width=""/&gt;
                    &lt;fo:table-body&gt;
                       &lt;fo:table-row&gt;
                          &lt;fo:table-cell padding-start="1pt" padding-end="1pt" padding-before="1pt" padding-after="1pt"
                                         padding-top="1pt"
                                         padding-bottom="1pt"&gt;
                             &lt;fo:block&gt; &lt;/fo:block&gt;
                          &lt;/fo:table-cell&gt;
  </code></pre>
  
  <p>(..etc)</p>
  
  <p><em>Note</em> the column-width is blank...</p>