Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2013, 09:02 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default Cals Table Colspec - HTML td

Dear All,

We have to assign the colspec align attributes which was set in Cals Table for their respective entry element as align attribute in HTML td element.

Additional Details
StyleSheet version: 2.0
Editor: Oxygen
Parser: Saxon-EE 9.2.1.2

XML File
Code:
<table frame="ALL" pgwide="0.9">
<tgroup cols="7" colsep="0" rowsep="0">
<colspec colname="1" colnum="1" colsep="1" colwidth="10*" rowsep="0" align="left"/>
<colspec colname="2" colnum="2" colsep="1" colwidth="15*" rowsep="0" align="center"/>
<colspec colname="3" colnum="3" colsep="1" colwidth="10*" rowsep="0" align="center"/>
<colspec colname="4" colnum="4" colsep="1" colwidth="10*" rowsep="0" align="center"/>
<colspec colname="5" colnum="5" colsep="1" colwidth="30*" rowsep="0" align="center"/>
<colspec colname="6" colnum="6" colsep="1" colwidth="10*" rowsep="0" align="center"/>
<colspec colname="7" colnum="7" colsep="1" colwidth="15*" rowsep="0" align="center"/>
<tbody valign="top">
<row>
<entry colname="1" colsep="0" rowsep="0" namest="1" nameend="7" align="center"><emph typestyle="bf">PAHANG<nl/><nl/>KEDUDUKAN PUSAT MENGUNDI<nl/><nl/>&#x0028;HARI MENGUNDI AWAL&#x0029;</emph></entry>
</row>
<row>
<entry colname="1" colsep="0" rowsep="0">P. 078 Cameron Highlands</entry>
<entry colname="2" colsep="0" rowsep="0">N. 01 Tanah Rata</entry>
<entry colname="3" colsep="0" rowsep="0">Kampung Raja</entry>
<entry colname="4" colsep="0" rowsep="0">078/01/02</entry>
<entry colname="5" colsep="0" rowsep="0" align="left">Bilik Maklumat Balai Polis Brinchang</entry>
<entry colname="6" colsep="0" rowsep="0">P.W. 3896 &#x0026; P.W. 3897</entry>
<entry colname="7" colsep="0" rowsep="0">8.00 am - 7.00 pm</entry>
</row>
<row>
<entry colname="1" colsep="0" rowsep="0"></entry>
<entry colname="2" colsep="0" rowsep="0"></entry>
<entry colname="3" colsep="0" rowsep="0">Teringkap</entry>
<entry colname="4" colsep="0" rowsep="0" align="left">078/01/06</entry>
<entry colname="5" colsep="0" rowsep="0">Bilik Maklumat Balai Polis Brinchang</entry>
<entry colname="6" colsep="0" rowsep="0">&#x201D;</entry>
<entry colname="7" colsep="0" rowsep="0">8.00 am - 7.00 pm</entry>
</row>
</tbody>
</tgroup>
</table>
XSL File
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:param name="default.table.width" select="'80%'"/>

<xsl:template match="table">
<xsl:variable name="tborder1">
<xsl:choose>
<xsl:when test="@frame='all'">border-top: 2px solid #ff0000; border-bottom: 2px solid #ff0000; border-left: 2px solid #ff0000; border-right: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='topbot'">border-top: 2px solid #ff0000; border-bottom: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='top'">border-top: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='bottom'">border-bottom: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='leftright'">border-left: 2px solid #ff0000; border-right: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='left'">border-left: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='right'">border-right: 2px solid #ff0000;</xsl:when>
<xsl:otherwise>0px 0px 0px 0px solid #000000;</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<br/><table bgcolor="#ffdecc" border="1" cellpadding="5" width="80%" align="center" cellspacing="0" style="{$tborder1}">
<xsl:apply-templates/>
</table><br/>


</xsl:template>
<xsl:template match="tgroup">
<br/> 
<xsl:if test="../@pgwide=1">
</xsl:if>

<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align"/>
</xsl:attribute>
</xsl:if>

<xsl:if test="@valign">
<xsl:attribute name="valign">
<xsl:value-of select="@valign"/>
</xsl:attribute>
</xsl:if>

<xsl:apply-templates/>
</xsl:template>


<xsl:template match="tbody">
<xsl:choose>
<xsl:when test="@valign='top'">
<tbody valign="top">
<xsl:apply-templates/>
</tbody>
</xsl:when>
<xsl:when test="@valign='middle'">
<tbody valign="middle">
<xsl:apply-templates/>
</tbody>
</xsl:when>
<xsl:otherwise>
<tbody valign="bottom">
<xsl:apply-templates/>
</tbody>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="thead">
<xsl:choose>
<xsl:when test="@valign='top'">
<thead valign="top">
<xsl:apply-templates/>
</thead>
</xsl:when>
<xsl:when test="@valign='middle'">
<thead valign="middle">
<xsl:apply-templates/>
</thead>
</xsl:when>
<xsl:otherwise>
<thead valign="bottom">
<xsl:apply-templates/>
</thead>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

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


<xsl:template match="tbody/row/entry">
<xsl:call-template name="process.cell">
<xsl:with-param name="cellgi">td</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template match="thead/row/entry">
<xsl:call-template name="process.cell">
<xsl:with-param name="cellgi">th</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template match="tfoot/row/entry">
<xsl:call-template name="process.cell">
<xsl:with-param name="cellgi">th</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template match="entry">
<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align"/>
</xsl:attribute>
</xsl:if>

<xsl:if test="@valign">
<xsl:attribute name="valign">
<xsl:value-of select="@valign"/>
</xsl:attribute>
</xsl:if>
</xsl:template>


<xsl:template name="process.cell">
<xsl:param name="cellgi">td</xsl:param>
<xsl:variable name="empty.cell" select="count(node()) = 0"/>


<xsl:element name="{$cellgi}">

<xsl:if test="@namest">
<xsl:attribute name="colspan"><xsl:value-of select="(@nameend) + (-(@namest)) + 1"/></xsl:attribute>
</xsl:if>

<xsl:if test="@morerows">
<xsl:attribute name="rowspan">
<xsl:value-of select="@morerows+1"/>
</xsl:attribute>
</xsl:if>

<xsl:if test="@align">
<xsl:attribute name="align">
<xsl:value-of select="@align"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@valign">
<xsl:attribute name="valign">
<xsl:value-of select="@valign"/>
</xsl:attribute>
</xsl:if>

<xsl:choose>
<xsl:when test="(@rowsep='1') and (@colsep='1')">
<xsl:attribute name="style">border-bottom:2px solid #0000ff; border-right:2px solid #0000ff</xsl:attribute>
</xsl:when>
<xsl:when test="(@rowsep='1') and (@colsep='0')">
<xsl:attribute name="style">border-bottom:2px solid #0000ff</xsl:attribute>
</xsl:when>
<xsl:when test="(@rowsep=0) and (@colsep=1)">
<xsl:attribute name="style">border-right:2px solid #0000ff</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="style">border: 0px 0px 0px 0pxsolid #0000ff;</xsl:attribute>
</xsl:otherwise>
</xsl:choose>


<xsl:if test="not(preceding-sibling::*)
and ancestor::row/@id">
<a name="{ancestor::row/@id}"/>
</xsl:if>

<xsl:if test="@id">
<a name="{@id}"/>
</xsl:if>

<xsl:choose>
<xsl:when test="$empty.cell">
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>

<xsl:template name="add-empty-entries">
<xsl:param name="number" select="'0'"/>
<xsl:choose>
<xsl:when test="$number &lt;= 0"></xsl:when>
<xsl:otherwise>
<td> </td>
<xsl:call-template name="add-empty-entries">
<xsl:with-param name="number" select="$number - 1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="colspec.colnum">
<xsl:param name="colspec" select="."/>
<xsl:choose>
<xsl:when test="$colspec/@colnum">
<xsl:value-of select="$colspec/@colnum"/>
</xsl:when>
<xsl:when test="$colspec/preceding-sibling::colspec">
<xsl:variable name="prec.colspec.colnum">
<xsl:call-template name="colspec.colnum">
<xsl:with-param name="colspec" select="$colspec/preceding-sibling::colspec[1]"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$prec.colspec.colnum + 1"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="generate.colgroup">
<xsl:param name="cols" select="1"/>
<xsl:param name="count" select="1"/>
<xsl:choose>
<xsl:when test="$count>$cols"></xsl:when>
<xsl:otherwise>
<xsl:call-template name="generate.col">
<xsl:with-param name="countcol" select="$count"/>
</xsl:call-template>
<xsl:call-template name="generate.colgroup">
<xsl:with-param name="cols" select="$cols"/>
<xsl:with-param name="count" select="$count+1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="generate.col">
<xsl:param name="countcol">1</xsl:param>
<xsl:param name="colspecs" select="./colspec"/>
<xsl:param name="count">1</xsl:param>
<xsl:param name="colnum">1</xsl:param>

<xsl:choose>
<xsl:when test="$count>count($colspecs)">
<col/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
<xsl:variable name="colspec.colnum">
<xsl:choose>
<xsl:when test="$colspec/@colnum">
<xsl:value-of select="$colspec/@colnum"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$colnum"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:choose>
<xsl:when test="$colspec.colnum=$countcol">
<col>
<xsl:if test="$colspec/@align">
<xsl:attribute name="align">
<xsl:value-of select="$colspec/@align"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$colspec/@char">
<xsl:attribute name="char">
<xsl:value-of select="$colspec/@char"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="$colspec/@charoff">
<xsl:attribute name="charoff">
<xsl:value-of select="$colspec/@charoff"/>
</xsl:attribute>
</xsl:if>
</col>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="generate.col">
<xsl:with-param name="countcol" select="$countcol"/>
<xsl:with-param name="colspecs" select="$colspecs"/>
<xsl:with-param name="count" select="$count+1"/>
<xsl:with-param name="colnum">
<xsl:choose>
<xsl:when test="$colspec/@colnum">
<xsl:value-of select="$colspec/@colnum + 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$colnum + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>

</xsl:template>

<xsl:template name="colspec.colwidth">
<!-- when this macro is called, the current context must be an entry -->
<xsl:param name="colname"></xsl:param>
<!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
<xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
<xsl:param name="count">1</xsl:param>
<xsl:choose>
<xsl:when test="$count>count($colspecs)"></xsl:when>
<xsl:otherwise>
<xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
<xsl:choose>
<xsl:when test="$colspec/@colname=$colname">
<xsl:value-of select="$colspec/@colwidth"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="colspec.colwidth">
<xsl:with-param name="colname" select="$colname"/>
<xsl:with-param name="colspecs" select="$colspecs"/>
<xsl:with-param name="count" select="$count+1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

HTML File
Code:
<table bgcolor="#ffdecc" border="1" cellpadding="5" width="80%" align="center" cellspacing="0" style="0px 0px 0px 0px solid 

#000000;">
<br/>
<tbody valign="top">
<tr>
<td colspan="7" align="center" style="border: 0px 0px 0px 0pxsolid #0000ff;">PAHANGKEDUDUKAN PUSAT MENGUNDI(HARI MENGUNDI AWAL)</td>
</tr>
<tr>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">P. 078 Cameron Highlands</td>	<!--Here we need respective colspec attribute-->
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">N. 01 Tanah Rata</td>	<!--Here we need respective colspec attribute-->
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">Kampung Raja</td>	<!--Here we need respective colspec attribute-->
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">078/01/02</td>	<!--Here we need respective colspec attribute-->
<td align="left" style="border: 0px 0px 0px 0pxsolid #0000ff;">Bilik Maklumat Balai Polis Brinchang</td>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">P.W. 3896 &amp; P.W. 3897</td>	<!--Here we need respective colspec attribute-->
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">8.00 am - 7.00 pm</td>	<!--Here we need respective colspec attribute-->
</tr>
<tr>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;"> </td>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;"> </td>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">Teringkap</td>
<td align="left" style="border: 0px 0px 0px 0pxsolid #0000ff;">078/01/06</td>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">Bilik Maklumat Balai Polis Brinchang</td>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">”</td>
<td style="border: 0px 0px 0px 0pxsolid #0000ff;">8.00 am - 7.00 pm</td>
</tr>
</tbody>
</table>
Any help is appreciated.

Thanks.
 
Old June 10th, 2013, 12:29 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default

Kindly advise how to assign colspec[@align] to its respective entry. Thanks.
 
Old June 17th, 2013, 01:09 AM
Authorized User
 
Join Date: May 2008
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rangeshram
Default

Dear All,

We have found solution. Hope this will helps someone.

<!--if the entry element has align attribute then select that attribute otherwise select tgroup colspec element whose colname attribute should match with entry colname i.e., ancestor::tgroup/colspec[@colname=current()/@colname]/@align-->
<xsl:choose>
<xsl:when test="string-length(@align)">
<xsl:attribute name="align">
<xsl:value-of select="@align"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="align">
<xsl:variable name="colspe" select="entry[@colname]"/>
<xsl:value-of select="ancestor::tgroup/colspec[@colname=current()/@colname]/@align"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>

XSL Code:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    
<xsl:param name="default.table.width" select="'100%'"/>

 <xsl:template match="table">
 <xsl:variable name="tborder1">
<xsl:choose>
<xsl:when test="@frame='all'">border-top: 2px solid #ff0000; border-bottom: 2px solid #ff0000; border-left: 2px solid #ff0000; border-right: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='topbot'">border-top: 2px solid #ff0000; border-bottom: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='top'">border-top: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='bottom'">border-bottom: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='leftright'">border-left: 2px solid #ff0000; border-right: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='left'">border-left: 2px solid #ff0000;</xsl:when>
<xsl:when test="@frame='right'">border-right: 2px solid #ff0000;</xsl:when>
<xsl:otherwise>0px 0px 0px 0px solid #000000;</xsl:otherwise>
</xsl:choose>
</xsl:variable>
    <br/><table bgcolor="#ffdecc" border="1" cellpadding="5" width="100%" align="center" cellspacing="0" style="{$tborder1}">
      <xsl:apply-templates/>
  </table><br/>
  
  
    </xsl:template>
  <xsl:template match="tgroup">
  <br/> 
    <xsl:if test="../@pgwide=1">
    </xsl:if>
<xsl:apply-templates/>
</xsl:template>


<xsl:template match="tbody">
  <xsl:choose>
<xsl:when test="@valign='top'">
  <tbody valign="top">
    <xsl:apply-templates/>
  </tbody>
  </xsl:when>
  <xsl:when test="@valign='middle'">
<tbody valign="middle">
  <xsl:apply-templates/>
  </tbody>
  </xsl:when>
  <xsl:otherwise>
<tbody valign="bottom">
  <xsl:apply-templates/>
  </tbody>
  </xsl:otherwise>
</xsl:choose>
</xsl:template>

  

<xsl:template match="thead">
 <xsl:choose>
<xsl:when test="@valign='top'">
  <thead valign="top">
    <xsl:apply-templates/>
  </thead>
  </xsl:when>
  <xsl:when test="@valign='middle'">
  <thead valign="middle">
  <xsl:apply-templates/>
  </thead>
  </xsl:when>
  <xsl:otherwise>
      <thead valign="bottom">
  <xsl:apply-templates/>
  </thead>
  </xsl:otherwise>
</xsl:choose>
 </xsl:template>

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


<xsl:template match="entry">
    <xsl:choose>
        <xsl:when test="ancestor::tbody">
            <xsl:call-template name="process.cell">
                <xsl:with-param name="cellgi">td</xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:when test="ancestor::thead">
            <xsl:call-template name="process.cell">
                <xsl:with-param name="cellgi">th</xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:when test="ancestor::tfoot">
            <xsl:call-template name="process.cell">
                <xsl:with-param name="cellgi">th</xsl:with-param>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="name(preceding-sibling::*[1])"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>


  <xsl:template name="process.cell">
  <xsl:param name="cellgi">td</xsl:param>


  <xsl:variable name="empty.cell" select="count(node()) = 0"/>
 
  <xsl:element name="{$cellgi}">

    <xsl:if test="@namest">
    <xsl:attribute name="colspan"><xsl:value-of select="(@nameend) + (-(@namest)) + 1"/></xsl:attribute>
    </xsl:if>

      <xsl:if test="@morerows">
      <xsl:attribute name="rowspan">
        <xsl:value-of select="@morerows+1"/>
      </xsl:attribute>
    </xsl:if>
    
    
    <xsl:if test="@valign">
      <xsl:attribute name="valign">
        <xsl:value-of select="@valign"/>
      </xsl:attribute>
    </xsl:if>
    
  <xsl:attribute name="width">
    <xsl:variable name="currColumn" select="@colname"/>
    <xsl:variable name="colwidth" select="ancestor::tgroup/colspec[@colname=$currColumn]/@colwidth"/>
    <xsl:choose>
        <xsl:when test="ends-with($colwidth, '*')">
            <xsl:value-of select="replace($colwidth, '\*', '%')"/>
        </xsl:when>
        <xsl:when test="not(ends-with($colwidth, '*'))">
            <xsl:value-of select="$colwidth"/><xsl:text>%</xsl:text>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$colwidth"/>
        </xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
    
    
    <xsl:choose>
      <xsl:when test="string-length(@align)">
        <xsl:attribute name="align">
          <xsl:value-of select="@align"/>
        </xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="align">
          <xsl:variable name="colspe" select="entry[@colname]"/>
          <xsl:value-of select="ancestor::tgroup/colspec[@colname=current()/@colname]/@align"/>
        </xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
    
    <xsl:choose>
    <xsl:when test="(@rowsep='1') and (@colsep='1')">
        <xsl:attribute name="style">border-bottom:2px solid #0000ff; border-right:2px solid #0000ff</xsl:attribute>
    </xsl:when>
    <xsl:when test="(@rowsep='1') and (@colsep='0')">
        <xsl:attribute name="style">border-bottom:2px solid #0000ff</xsl:attribute>
    </xsl:when>
    <xsl:when test="(@rowsep=0) and (@colsep=1)">
        <xsl:attribute name="style">border-right:2px solid #0000ff</xsl:attribute>
    </xsl:when>
    <xsl:otherwise>
        <xsl:attribute name="style">border: 0px 0px 0px 0pxsolid #0000ff;</xsl:attribute>
    </xsl:otherwise>
    </xsl:choose>

    <xsl:if test="not(preceding-sibling::*)
                  and ancestor::row/@id">
      <a name="{ancestor::row/@id}"/>
    </xsl:if>

    <xsl:if test="@id">
      <a name="{@id}"/>
    </xsl:if>

    <xsl:choose>
      <xsl:when test="$empty.cell">
        <xsl:text> </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:element>
  </xsl:template>
  
<xsl:template name="add-empty-entries">
  <xsl:param name="number" select="'0'"/>
  <xsl:choose>
    <xsl:when test="$number &lt;= 0"></xsl:when>
    <xsl:otherwise>
      <td> </td>
      <xsl:call-template name="add-empty-entries">
        <xsl:with-param name="number" select="$number - 1"/>
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="colspec.colnum">
  <xsl:param name="colspec" select="."/>
  <xsl:choose>
    <xsl:when test="$colspec/@colnum">
      <xsl:value-of select="$colspec/@colnum"/>
    </xsl:when>
    <xsl:when test="$colspec/preceding-sibling::colspec">
      <xsl:variable name="prec.colspec.colnum">
        <xsl:call-template name="colspec.colnum">
          <xsl:with-param name="colspec" select="$colspec/preceding-sibling::colspec[1]"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="$prec.colspec.colnum + 1"/>
    </xsl:when>
    <xsl:otherwise>1</xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="generate.colgroup">
  <xsl:param name="cols" select="1"/>
  <xsl:param name="count" select="1"/>
  <xsl:choose>
    <xsl:when test="$count>$cols"></xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="generate.col">
        <xsl:with-param name="countcol" select="$count"/>
      </xsl:call-template>
      <xsl:call-template name="generate.colgroup">
        <xsl:with-param name="cols" select="$cols"/>
        <xsl:with-param name="count" select="$count+1"/>
      </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="generate.col">
  <xsl:param name="countcol">1</xsl:param>
  <xsl:param name="colspecs" select="./colspec"/>
  <xsl:param name="count">1</xsl:param>
  <xsl:param name="colnum">1</xsl:param>

  <xsl:choose>
    <xsl:when test="$count>count($colspecs)">
      <col/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
      <xsl:variable name="colspec.colnum">
        <xsl:choose>
          <xsl:when test="$colspec/@colnum">
            <xsl:value-of select="$colspec/@colnum"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$colnum"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:choose>
        <xsl:when test="$colspec.colnum=$countcol">
          <col>
            <xsl:if test="$colspec/@align">
              <xsl:attribute name="align">
                <xsl:value-of select="$colspec/@align"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:if test="$colspec/@char">
              <xsl:attribute name="char">
                <xsl:value-of select="$colspec/@char"/>
              </xsl:attribute>
            </xsl:if>
            <xsl:if test="$colspec/@charoff">
              <xsl:attribute name="charoff">
                <xsl:value-of select="$colspec/@charoff"/>
              </xsl:attribute>
            </xsl:if>
          </col>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="generate.col">
            <xsl:with-param name="countcol" select="$countcol"/>
            <xsl:with-param name="colspecs" select="$colspecs"/>
            <xsl:with-param name="count" select="$count+1"/>
            <xsl:with-param name="colnum">
              <xsl:choose>
                <xsl:when test="$colspec/@colnum">
                  <xsl:value-of select="$colspec/@colnum + 1"/>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="$colnum + 1"/>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:with-param>
           </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>

<xsl:template name="colspec.colwidth">
  <!-- when this macro is called, the current context must be an entry -->
  <xsl:param name="colname"></xsl:param>
  <!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
  <xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
  <xsl:param name="count">1</xsl:param>
  <xsl:choose>
    <xsl:when test="$count>count($colspecs)"></xsl:when>
    <xsl:otherwise>
      <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
      <xsl:choose>
        <xsl:when test="$colspec/@colname=$colname">
          <xsl:value-of select="$colspec/@colwidth"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="colspec.colwidth">
            <xsl:with-param name="colname" select="$colname"/>
            <xsl:with-param name="colspecs" select="$colspecs"/>
            <xsl:with-param name="count" select="$count+1"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template match="nl">
        <br/><xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>
Note: If it helps then vote thanks.
Thanks,
Ram

Last edited by rangeshram; June 17th, 2013 at 01:12 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cals table to Html table XSLT ROCXY XSLT 6 July 13th, 2010 11:56 AM
very urgent:cals table to indesign table using xsl franklinclinton XSLT 1 December 16th, 2009 03:48 PM
CALS to HTML Transformation RussellKay XSLT 1 May 11th, 2009 06:46 AM
Aligning table data according to "colspec" element simone_s XSLT 0 April 25th, 2006 12:13 AM
rephrased question - for variable inside HTML <td> crmpicco Classic ASP Basics 1 February 11th, 2005 04:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.