xsl-list
[Top] [All Lists]

RE: Dynamic Table

2004-12-23 10:56:40
It works great! Thanks to you and Pieter for your help...

Regards,
François

-----Original Message-----
From: Marian Olteanu [mailto:mou_softwin(_at_)yahoo(_dot_)com] 
Sent: lundi 20 décembre 2004 19:42
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Dynamic Table

Try this:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html"/>

<xsl:param name="widthTable" select="3"/> <xsl:param name="widthCell" 
select="3"/>

<xsl:template match="/">
        <table>
                <xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
                <xsl:call-template name="processNode">
                        <xsl:with-param name="node" 
select="/domain/variable[1]"/>
                        <xsl:with-param name="usedCols" select="0"/>
                </xsl:call-template>
                <xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
        </table>
</xsl:template>

<xsl:template name="processNode">
        <xsl:param name="node"/>
        <xsl:param name="usedCols" select="0"/>
        
        <xsl:variable name="nodeWidth" select="string-length( normalize-space( 
$node/text() ) )"/>
        <xsl:variable name="nodeWidthInCells">
                <xsl:choose>
                        <xsl:when test="$nodeWidth mod $widthCell = 0">
                                <xsl:value-of select="$nodeWidth div 
$widthCell"/>
                        </xsl:when>
                        <xsl:otherwise>
                                <xsl:value-of select="1 + floor($nodeWidth div 
$widthCell)"/>
                        </xsl:otherwise>
                </xsl:choose>
        </xsl:variable>
        <!-- check if new line -->
        <xsl:if test="( $widthTable - $usedCols ) &lt; $nodeWidthInCells ">
                <xsl:text disable-output-escaping="yes">&lt;/tr&gt;</xsl:text>
                <xsl:text disable-output-escaping="yes">&lt;tr&gt;</xsl:text>
        </xsl:if>

        <td>
                <xsl:if test="$nodeWidthInCells &gt; 1">
                        <xsl:attribute name="colspan">
                                <xsl:value-of select="$nodeWidthInCells"/>
                        </xsl:attribute>
                </xsl:if>
                <xsl:value-of select="normalize-space( $node/text() )"/>
        </td>


        <xsl:if test="$node/following-sibling::variable[1]">
                <xsl:call-template name="processNode">
                        <xsl:with-param name="node" 
select="$node/following-sibling::variable[1]"/>
                        <xsl:with-param name="usedCols">
                                <xsl:choose>
                                        <xsl:when test="( $widthTable - 
$usedCols ) &lt; $nodeWidthInCells ">
                                                <xsl:value-of 
select="$nodeWidthInCells"/>
                                        </xsl:when>
                                        <xsl:otherwise>
                                                <xsl:value-of 
select="$nodeWidthInCells + $usedCols"/>
                                        </xsl:otherwise>
                                </xsl:choose>
                        </xsl:with-param>
                </xsl:call-template>
        </xsl:if>
</xsl:template>
</xsl:stylesheet>



--- Pieter Reint Siegers Kort <pieter(_dot_)siegers(_at_)elnorte(_dot_)com> 
wrote:

Hi François,

Check out:
http://www.dpawson.co.uk/xsl/sect2/N7450.html

HTH,
<prs/>

-----Original Message-----
From: François Torche [mailto:torche(_at_)i-minds(_dot_)be]
Sent: Monday, December 20, 2004 11:21 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Dynamic Table

Hello,

I have a very basic XML document that looks like:
<domain>
  <variable> abc </variable>
  <variable> def </variable>
  <variable> ghi </variable>
  <variable> abcdefgh </variable>
  <variable> abcdef </variable>
  <variable> abc </variable>
  ...
</domain>

And I would like to create an HTML table with, for example, 3 columns. 
Each column can contain 3 characters max. The result of my 
transformation should look like:
<table>
  <tr>
    <td> abc </td>
    <td> def </td>
    <td> def </td>
  </tr>
  <tr>
    <td colspan = "3"> abcdefgh </td>
  </tr>
  <tr>
    <td colspan = "2"> abcdef </td>
    <td> abc </td>
  </tr>
</table>

I don't have a clue how to dynamically determine the colspan attribute 
and start a new row if there is not enough room to put the content of 
a variable.

Many thanks in advance for your help,
François

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




=====
Marian
http://www.utdallas.edu/~mgo031000/


                
__________________________________
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail

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



<Prev in Thread] Current Thread [Next in Thread>