[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Incorrect colname attribute value in case of rows

Subject: RE: Incorrect colname attribute value in case of rowspan attribute presence in html while HTML to CALS Table Transformation
From: "Praveen Chauhan" <Praveen.Chauhan@xxxxxxxxxxxxxx>
Date: Mon, 30 Apr 2012 15:11:24 +0530
RE:   Incorrect colname attribute value in case of rows
Hi Joga Ji,

Below link may be useful:

http://stackoverflow.com/questions/4626873/html-to-cals-tables




Thanks
Praveen Chauhan

-----Original Message-----
From: Joga Singh Rawat [mailto:jrawat@xxxxxxxxxxxxxx]
Sent: Monday, April 30, 2012 11:01 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Incorrect colname attribute value in case of rowspan
attribute presence in html while HTML to CALS Table Transformation

Hi  Michael,
Solution provided by you is good but my question is totally different from
this.

Thanks
...JSR


-----Original Message-----
From: Joga Singh Rawat [mailto:jrawat@xxxxxxxxxxxxxx]
Sent: Sunday, April 29, 2012 10:59 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Incorrect colname attribute value in case of rowspan
attribute presence in html while HTML to CALS Table Transformation

HI Everybody,
I am converting plain html table to cals table. I have calculated 'colspan'
into 'spanname' correctly but I don't have any clue to transform 'rowspan'.

Please let me know any clue. Below is INPUT, XSLT, OUTPUT and Required
output


Input:
<div class="divTable">
<table class="numtable" id="table2">
  <tbody>
   <tr>
    <td class="tch rowspan="2">col1</td>                    
    <td class="tch" colspan="3">col2-4</td>
   </tr>
   <tr>
    <td class="tch">col2</td>
    <td class="tch">col3</td>
    <td class="tch">col4</td>
   </tr>
   <tr>
    <td class="tch">col1</td>
    <td class="tch">col2</td>
    <td class="tch">col3</td>
    <td class="tch">col4</td>
   </tr>                                 
   <tr>
    <td class="tch">col1</td>                   
    <td class="tch" rowspan="3">col2</td>
    <td class="tch" colspan="2">col3-4</td>
   </tr>
   <tr>
    <td class="tch">col1</td>
    <td class="tch">col3</td>
    <td class="tch">col4</td>
   </tr>
   <tr>
    <td class="tch">col1</td>
    <td class="tch">col3</td>
    <td class="tch">col4</td>
    </tr>
   </tbody>
  </table>
</div>


XSLT
<xsl:template match="td">
 <entry>
  <xsl:call-template name="colname-spanname"/>
  <xsl:apply-templates/>
 </entry>
</xsl:template>

<xsl:template name="colname-spanname">
  <xsl:if test="not(@colspan)">
   <xsl:attribute name="colname">
    <xsl:text>col</xsl:text>
    <xsl:if test="not(preceding-sibling::td[@colspan])">
     <xsl:value-of select="count(preceding-sibling::td)+1"/>
    </xsl:if>
    <xsl:if test="preceding-sibling::td[@colspan]">
     <xsl:variable name="colspan_values"
select="sum(preceding-sibling::td[@colspan]/@colspan)"/>
     <xsl:variable name="td_number" select="count(preceding-sibling::td)"/>
     <xsl:variable name="colspan_td_number"
select="count(preceding-sibling::td[@colspan])"/>
     <xsl:value-of select="($td_number+$colspan_values+1) -
$colspan_td_number"/>
    </xsl:if>
   </xsl:attribute>
  </xsl:if>
  <xsl:if test="@colspan">
   <xsl:attribute name="spanname">
    <xsl:if test="not(preceding-sibling::td[@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)+@colspan"/>
    </xsl:if>
    <xsl:if test="preceding-sibling::td[@colspan]">
     <xsl:variable name="colspan_values"
select="sum(preceding-sibling::td[@colspan]/@colspan)"/>
     <xsl:variable name="td_number" select="count(preceding-sibling::td)"/>
     <xsl:variable name="colspan_number"
select="count(preceding-sibling::td[@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+@colspan) - 1"/>
    </xsl:if>
   </xsl:attribute>
   <xsl:attribute name="namest">
    <xsl:text>col</xsl:text>
    <xsl:if test="not(preceding-sibling::td[@colspan])">
     <xsl:value-of select="count(preceding-sibling::td)+1"/>
    </xsl:if>
    <xsl:if test="preceding-sibling::td[@colspan]">
     <xsl:value-of
select="count(preceding-sibling::td[not(@colspan)])+sum(preceding-sibling::t
d[@colspan]/@colspan)+1"/>
    </xsl:if>
   </xsl:attribute>
   <xsl:attribute name="nameend">
    <xsl:text>col</xsl:text>
    <xsl:if test="not(preceding-sibling::td[@colspan])">
     <xsl:value-of select="count(preceding-sibling::td)+@colspan"/>
    </xsl:if>
    <xsl:if test="preceding-sibling::td[@colspan]">
     <xsl:value-of
select="count(preceding-sibling::td[not(@colspan)])+sum(preceding-sibling::t
d[@colspan]/@colspan)+@colspan"/>
    </xsl:if>
   </xsl:attribute>
  </xsl:if>
 </xsl:template>

<xsl:template name="max_column">
  <xsl:if test="not(descendant::td[@colspan][not(@class='Table_Caption' or
@class='Table_caption')][not(@class='Table_Subtitle' or
@class='Table_subtitle')])">
   <xsl:value-of select="for $x in descendant::tbody return (max((for $y in
descendant::tr[not(child::td[@class='Table_Caption' or
@class='Table_caption'])][not(child::td[@class='Table_Subtitle' or
@class='Table_subtitle'])] return count($y/td))))"/>
  </xsl:if>
  <xsl:if test="descendant::td[@colspan][not(@class='Table_Caption' or
@class='Table_caption')][not(@class='Table_Subtitle' or
@class='Table_subtitle')]">
   <xsl:variable name="tr_without_colspan" as="xsd:integer?">
    <xsl:value-of select="for $x in descendant::tbody return if
(descendant::tr[not(child::td[@colspan])]) then (max((for $y in
descendant::tr[not(child::td[@colspan])][not(child::td[@class='Table_Caption
' or @class='Table_caption'])][not(child::td[@class='Table_Subtitle' or
@class='Table_subtitle'])] return count($y/td)))) else 0"/>
   </xsl:variable>
   <xsl:variable name="tr_with_colspan" as="xsd:integer?">
    <xsl:value-of select="for $x in descendant::tbody return (max((for $y in
descendant::tr[child::td[@colspan]][not(child::td[@class='Table_Caption' or
@class='Table_caption'])][not(child::td[@class='Table_Subtitle' or
@class='Table_subtitle'])] return number(count($y/td[not(@colspan)]) +
sum($y/td/@colspan)))))"/>
   </xsl:variable>
   <xsl:value-of select="max(($tr_with_colspan,$tr_without_colspan))"/>
  </xsl:if>
 </xsl:template>

Output:
<table id="FileName_table2">
  <tgroup cols="4">      
   <thead>
    <row>
     <entry colname="col1" morerows="1">col1</entry>
     <entry spanname="2to4" namest="col2" nameend="col4">col2-4</entry>
    </row>
    <row>
     <entry colname="col1">col2</entry>
     <entry colname="col2">col3</entry>
     <entry colname="col3">col4</entry>
    </row>
    <row>
     <entry colname="col1">col1</entry>
     <entry colname="col2">col2</entry>
     <entry colname="col3">col3</entry>
     <entry colname="col4">col4</entry>
    </row>
    <row>
     <entry colname="col1">col1</entry>
     <entry colname="col2" morerows="2">col2</entry>
     <entry spanname="3to4" namest="col3" nameend="col4">col3-4</entry>
    </row>
    <row>
     <entry colname="col1">col1</entry>
     <entry colname="col2">col3</entry>
     <entry colname="col3">col4</entry>
    </row>
    <row>
     <entry colname="col1">col1</entry>
     <entry colname="col2">col3</entry>
     <entry colname="col3">col4</entry>
    </row>
   </thead>
  </tgroup>
</table>

Required Output:
<table id="FileName_table2">
 <tgroup cols="4">      
  <thead>
   <row>
    <entry colname="col1" morerows="1">col1</entry>
    <entry spanname="2to4" namest="col2" nameend="col4">col2-4</entry>
   </row>
   <row>
    <entry colname="col2">col2</entry>
    <entry colname="col4">col3</entry>
    <entry colname="col4">col4</entry>
   </row>
   <row>
    <entry colname="col1">col1</entry>
    <entry colname="col2">col2</entry>
    <entry colname="col3">col3</entry>
    <entry colname="col4">col4</entry>
   </row>
   <row>
    <entry colname="col1">col1</entry>
    <entry colname="col2" morerows="2">col2</entry>
    <entry spanname="3to4" namest="col3" nameend="col4">col3-4</entry>
   </row>
   <row>
    <entry colname="col1">col1</entry>
    <entry colname="col3">col3</entry>
    <entry colname="col4">col4</entry>
   </row>
   <row>
    <entry colname="col1">col1</entry>
    <entry colname="col3">col3</entry>
    <entry colname="col4">col4</entry>
   </row>
  </thead>
 </tgroup>
</table>

Thanks
...JSR

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.