xsl-list
[Top] [All Lists]

RE: [xsl] Re: HTML table colspec and spanspec problem

2010-01-22 02:47:14
I took a look at the input and output you sent... please check yourself
but the samples are  totally incorrect and there is no way that xslt
transforms your input into the currentoutput...

Please reply to this thread with correct INDENTED samples after you
remove previous content in order to keep the mail small.

Robby Pelssers

-----Original Message-----
From: Siddhi Thakkar [mailto:siddhi(_dot_)thakkar(_at_)aptaracorp(_dot_)com] 
Sent: Friday, January 22, 2010 6:40 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Re: HTML table colspec and spanspec problem

Hello there,
This is practically the first time that I am posting to this list, so 
aplogies if I have broken any of the rules.
I have an HTML table where in I need to create colspec and spanspec,
please 
see if you can help. I have been scratching my head on this for a week
now 
but couldn't even reach close to it. I understand that the code and
examples 
below are too lengthy to go through, but please help. I should be able
to go 
forward even if somebody could provide me with a logical hint. Thanks
very 
much. I could have posted the code I tried but just wanted to avoid
making 
my whole query less lengthy and less complicated.

INPUT XML FILE:
<table>
<tbody>
<tr>
<td class="tch" align="left">1</td>
<td class="tch" colspan="9" align="right">2</td>
</tr>
<tr>
<td class="tch" align="left">4</td>
<td class="tch" align="left">5</td>
<td class="tch" align="center">6</td>
<td class="tch" align="center">7</td>
<td class="tch" colspan="5" align="left">8</td>
<td class="tch" align="left">9</td>
</tr>
<tr>
<td class="tb" align="left">10</td>
<td class="tb" colspan="9" align="right">11</td>
</tr>
<tr>
<td class="tb" align="left">12</td>
<td class="tb" align="left">13</td>
<td class="tb" colspan="3" align="right">14</td>
<td class="tb" align="left">15</td>
<td class="tb" colspan="2" align="left">16</td>
</tr>
</tbody>
</table>


CURRENT OUTPUT:
<table>
<tgroup cols="10">
<thead>
<row>
<entry class="tch" align="left" name="col1">1</entry>
<entry class="tch" colspan="9" align="right" name="col2to10">2</entry>
</row>
<row>
<entry class="tch" align="left" name="col1">4</entry>
<entry class="tch" align="left" name="col2">5</entry>
<entry class="tch" align="center" name="col3">6</entry>
<entry class="tch" align="center" name="col4">7</entry>
<entry class="tch" colspan="5" align="left" name="col5to9">8</entry>
<entry class="tch" align="left" name="col10">9</entry>
</row>
</thead>
<tbody>
<row>
<entry class="tb" align="left" name="col1">10</entry>
<entry class="tb" colspan="9" align="right" name="col2to10">11</entry>
</row>
<row>
<entry class="tb" align="left" name="col1">12</entry>
<entry class="tb" align="left" name="col2">13</entry>
<entry class="tb" colspan="3" align="right" name="col3to5">14</entry>
<entry class="tb" align="left" name="col6">15</entry>
<entry class="tb" colspan="2" align="left" name="col7to8">16</entry>
</row>
</tbody>
</tgroup>
</table>

DESIRED OUTPUT:
<table>
<tgroup cols="10">
<!--value of name should be same as the row name, value of align should
be 
the string that has occurred maximum times in rows. For instance, in
this 
example there are four "col1" one inside each row, three of which have 
"left" as the value of align and one has "right", so colspec name="col1"

should have align="left" because it has the maximum occurence of the
two. If 
all the occurences would have been equal, we could have picked any.
There 
could be as many values of align as it is allowed to.-->
<colspec name="col1" align="left"/>
<colspec name="col2" align="left"/>
<colspec name="col3" align="center"/>
<colspec name="col4" align="center"/>
<colspec name="col6" align="left"/>
<colspec name="col10" align="left"/>
<spanspec name="col2to10" align="right"/>
<spanspec name="col3to5" align="right"/>
<spanspec name="col5to9" align="left"/>
<spanspec name="col7to8" align="left"/>
<thead>
<row>
<entry class="tch" align="left" name="col1">1</entry>
<entry class="tch" colspan="9" align="right" name="col2to10">2</entry>
</row>
<row>
<entry class="tch" align="left" name="col1">4</entry>
<entry class="tch" align="left" name="col2">5</entry>
<entry class="tch" align="center" name="col3">6</entry>
<entry class="tch" align="center" name="col4">7</entry>
<entry class="tch" colspan="5" align="left" name="col5to9">8</entry>
<entry class="tch" align="left" name="col10">9</entry>
</row>
</thead>
<tbody>
<row>
<entry class="tb" align="right" name="col1">10</entry>
<entry class="tb" colspan="9" align="right" name="col2to10">11</entry>
</row>
<row>
<entry class="tb" align="left" name="col1">12</entry>
<entry class="tb" align="left" name="col2">13</entry>
<entry class="tb" colspan="3" align="right" name="col3to5">14</entry>
<entry class="tb" align="left" name="col6">15</entry>
<entry class="tb" colspan="2" align="left" name="col7to8">16</entry>
</row>
</tbody>
</tgroup>
</table>


CURRENT CODE:

<xsl:template match="table">
<table>
<tgroup>
<xsl:apply-templates/>
</tgroup>
</table>
</xsl:template>

<xsl:template match="tr">
<xsl:if 
test="child::td[(_at_)class='tch'][not(preceding::tr[1][child::td[(_at_)class='tch
']])]">
<thead>
<row>
<xsl:apply-templates/>
</row>
<!--code to group all class="tch" appearing together as thead-->
</thead>
</xsl:if>
<xsl:if 
test="child::td[(_at_)class='tbtm'][not(preceding::tr[1][child::td[(_at_)class='tb
tm']])]">
<tfoot>
<row>
<xsl:apply-templates/>
</row>
<!--code to group all class="tbtm" appearing together as tfoot-->
</tfoot>
</xsl:if>
<xsl:if 
test="child::td[(_at_)class='tb'][not(preceding::tr[1][child::td[(_at_)class='tb']
])]">
<tbody>
<row>
<xsl:apply-templates/>
</row>
<!--code to group all class="tb" appearing together as tbody-->
</tbody>
</xsl:if>
</xsl:template>

<xsl:template match="tbody">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="td">
<entry>
<xsl:attribute name="class">
<xsl:value-of select="@class"/>
</xsl:attribute>
<xsl:if test="@colspan">
<xsl:attribute name="colspan">
<xsl:value-of select="@colspan"/>
</xsl:attribute>
</xsl:if>
<!--following is the code to generate value of name attribute, the
values of 
name attribute of colspec and spanspec should be same as the values 
generated by the code below-->
<xsl:attribute name="name">
<xsl:text>col</xsl:text>
<xsl:if test="not(@colspan)">
<xsl:if test="not(preceding-sibling::td[(_at_)colspan])">
<xsl:value-of select="count(preceding-sibling::td)+1"/>
</xsl:if>
<xsl:if test="preceding-sibling::td[(_at_)colspan]">
<xsl:variable name="colspan_values" 
select="sum(preceding-sibling::td[(_at_)colspan]/@colspan)"/>
<xsl:variable name="td_number" select="count(preceding-sibling::td)"/>
<xsl:variable name="colspan_td_number" 
select="count(preceding-sibling::td[(_at_)colspan])"/>
<xsl:value-of select="($td_number+$colspan_values+1) -
$colspan_td_number"/>
</xsl:if>
</xsl:if>
<xsl:if test="@colspan">
<xsl:if test="not(preceding-sibling::td[(_at_)colspan])">
<xsl:value-of select="count(preceding-sibling::td)+1"/>
<xsl:text>to</xsl:text>
<xsl:variable name="td_number" select="count(preceding-sibling::td)"/>
<xsl:variable name="colspan" select="@colspan"/>
<xsl:value-of select="count(preceding-sibling::td)+(_at_)colspan"/>
</xsl:if>
<xsl:if test="preceding-sibling::td[(_at_)colspan]">
<xsl:variable name="colspan_values" 
select="sum(preceding-sibling::td[(_at_)colspan]/@colspan)"/>
<xsl:variable name="td_number" select="count(preceding-sibling::td)"/>
<xsl:variable name="colspan_number" 
select="count(preceding-sibling::td[(_at_)colspan])"/>
<xsl:variable name="starting_value">
<xsl:value-of select="($td_number+$colspan_values+1) -
$colspan_number"/>
</xsl:variable>
<xsl:value-of select="$starting_value"/>
<xsl:text>to</xsl:text>
<xsl:value-of select="$starting_value+(_at_)colspan - 1"/>
</xsl:if>
</xsl:if>
</xsl:attribute>
<xsl:apply-templates/>
</entry>
</xsl:template>


<xsl:template match="p">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>



Thanks again,
Siddhi 



--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--