xsl-list
[Top] [All Lists]

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

2006-06-26 00:20:00
Hi Byomkesh,
  This is easier in XSLT 2.0. Below is the XSLT 2.0 solution (tested
with Saxon 8.7.3J):

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

   <xsl:output method="xml" indent="yes" />

   <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/td)" />
           </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:stylesheet>

The stylesheet dynamically finds the column percentages depending on
the amount of content in table cells across the whole Table.

The table.html tag is not clear to me. I have done something with it.
Hope you can tinker the stylesheet.

Regards,
Mukul

On 6/24/06, Byomkesh <bkesh(_at_)eztechgroup(_dot_)net> wrote:
Dear All,

I have one xml file. I want count cell and divide percentage in between cell
(through XSL). Please any one help me.

XML File
-------------

<table border="0" cellspacing="0" cellpadding="1" width="90%">
<thead>
<tr>
<th valign="top" colspan="3">Table 1.1 802.11b Channels</b></th>
</tr>
<tr>
<th>Channel Number</th>
<th>Center Frequency (in GHz)</th>
<th>USA</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2.412</td>
<td>&#x2713;</td>
</tr>
</tbody>
</table>

I want OutPut
-----------------

<table>
<table.html frame="void" width="100%" rules="groups" align="left">
<colgroup>
<col width="50%"/>
<col width="30%"/>
<col width="20%"/>
</colgroup>
<!-- Rest of the taging as it is -->
<thead>
<tr>
<th valign="top" colspan="3">Table 1.1 802.11b Channels</b></th>
</tr>
<tr>
<th>Channel Number</th>
<th>Center Frequency (in GHz)</th>
<th>USA</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2.412</td>
<td>&#x2713;</td>
</tr>
</tbody>
</table>

Regards,

Byomkesh

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--