RE: [xsl] How count the Table cell (Cals Table) using XSL

Subject: RE: [xsl] How count the Table cell (Cals Table) using XSL
From: "Byomokesh" <bkesh@xxxxxxxxxxxxxxx>
Date: Mon, 10 Jul 2006 15:01:59 +0530
Hi,

I tried many option, but did not found solution. Same Validation Error
showing. If I have convert one table, it can easily converted. But If I
have paste another table in same file, then showing validation Error.

This Error is --
=======================================================
Validation error
  FORG0001: Cannot convert string "" to a double
Transformation failed: Run-time errors were reported
=======================================================


What is the reason?

This is my XML File
--------------------

<p>Table 1.3 shows the relative FCC and IEEE power output limits.</p>
<table border="0" cellspacing="0" cellpadding="1" width="90%">
<thead>
<tr>
<th valign="top" colspan="9"><b>Table 1.1 802.11b Channels</b></th>
</tr>
<tr>
<th valign="top"><b>Channel Number</b></th>
<th valign="top"><b>Center Frequency (in GHz)</b></th>
<th valign="top"><b>USA</b></th>
<th valign="top"><b>Europe</b></th>
<th valign="top"><b>Spain</b></th>
<th valign="top"><b>France</b></th>
<th valign="top"><b>Israel</b></th>
<th valign="top"><b>China</b></th>
<th valign="top"><b>Japan</b></th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">1</td>
<td valign="top">2.412</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
</tr>
<tr><td valign="top">2</td>
<td valign="top">2.417</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">3</td>
<td valign="top">2.422</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">4</td>
<td valign="top">2.427</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">5</td>
<td valign="top">2.432</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">6</td>
<td valign="top">2.437</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">7</td>
<td valign="top">2.442</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">8</td>
<td valign="top">2.447</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">9</td>
<td valign="top">2.452</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">10</td>
<td valign="top">2.457</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">11</td>
<td valign="top">2.462</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">12</td>
<td valign="top">2.467</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">13</td>
<td valign="top">2.472</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td></tr>
<tr><td valign="top">14</td>
<td valign="top">2.484</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x00A0;</td>
<td valign="top">&#x2713;</td></tr>
</tbody>
</table>
<p>more columns</p>
<table border="0" cellspacing="0" cellpadding="1" width="90%">
<thead>
<tr>
<th valign="top"><b>Channel Number</b></th>
<th valign="top"><b>Center Frequency (in GHz)</b></th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">36</td>
<td valign="top">5.180</td>
</tr>
<tr>
<td valign="top">40</td>
<td valign="top">5.200</td>
</tr>
<tr>
<td valign="top">44</td>
<td valign="top">5.220</td>
</tr>
<tr>
<td valign="top">48</td>
<td valign="top">5.240</td>
</tr>
<tr>
<td valign="top">52</td>
<td valign="top">5.260</td>
</tr>
<tr>
<td valign="top">56</td>
<td valign="top">5.280</td>
</tr>
<tr>
<td valign="top">60</td>
<td valign="top">5.300</td>
</tr>
<tr>
<td valign="top">64</td>
<td valign="top">5.320</td>
</tr>
<tr>
<td valign="top">149</td>
<td valign="top">5.745</td>
</tr>
</tbody>
</table>

XSL File:----
--------------

<xsl:template match="table">
      <table>
        <table.html frame="void" width="100%" rules="groups"
align="left" />
        <xsl:variable name="rtf">
           <xsl:call-template name="FindMaxStringLength">
              <xsl:with-param name="n"
select="count(//tr[5]/td|//tr[5]/th)" />
           </xsl:call-template>
        </xsl:variable>


        <colgroup>
          <xsl:for-each select="$rtf/x">

<col width="{format-number(((. div (sum(../*))) * 100),'##.##')}%"/>
          </xsl:for-each>
        </colgroup>

        <xsl:copy-of select="*" />
      </table>
   </xsl:template>


   <xsl:template name="FindMaxStringLength">
       <xsl:param name="n" />
      <xsl:if test="$n &gt; 0">
          <x>
	    <xsl:for-each select="//tr[2]/th[$n] | //tr/td[$n]">
               <xsl:sort select="string-length(.)" order="descending" />
               <xsl:if test="position() = 1">
                   <xsl:value-of select="string-length(.)" />
               </xsl:if >
            </xsl:for-each>
          </x>
          <xsl:call-template name="FindMaxStringLength">
             <xsl:with-param name="n" select="$n - 1" />
          </xsl:call-template>
       </xsl:if>

</xsl:template>


<xsl:template match="tr"> 
<xsl:text>&#xa;</xsl:text><tr>
<xsl:apply-templates/>
</tr>
</xsl:template>

<xsl:template match="td"> 
<xsl:text>&#xa;</xsl:text><td>
<xsl:apply-templates/>
</td>
</xsl:template>

<xsl:template match="th"> 
<xsl:text>&#xa;</xsl:text><th>
<xsl:apply-templates/>
</th>
</xsl:template>

<xsl:template match="thead"> 
<xsl:text>&#xa;</xsl:text><thead>
<xsl:apply-templates/>
</thead>
</xsl:template>

<xsl:template match="tbody"> 
<xsl:text>&#xa;</xsl:text><tbody>
<xsl:apply-templates/>
</tbody>
</xsl:template>

Thanks,

Byomkesh

Current Thread