|
Subject: Re: [xsl] How count the Table cell (Cals Table) using XSL From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Mon, 26 Jun 2006 12:49:30 +0530 |
Hi Byomkesh, This is easier in XSLT 2.0. Below is the XSLT 2.0 solution (tested with Saxon 8.7.3J):
<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 > 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>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
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>✓</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>✓</td> </tr> </tbody> </table>
Regards,
Byomkesh
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] How count the Table cell (Cal, Byomkesh | Thread | Re: [xsl] How count the Table cell , Byomkesh |
| Re: [xsl] Accessing elements with k, Tim Lebo | Date | Re: [xsl] returning nodes (not a st, David Carlisle |
| Month |