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

RE: Dynamic Table

Subject: RE: Dynamic Table
From: François Torche <torche@xxxxxxxxxx>
Date: Thu, 23 Dec 2004 18:56:40 +0100
xsl dynamic table
It works great! Thanks to you and Pieter for your help...

Regards,
Frangois

-----Original Message-----
From: Marian Olteanu [mailto:mou_softwin@xxxxxxxxx]
Sent: lundi 20 dicembre 2004 19:42
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  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.siegers@xxxxxxxxxxx> wrote:

> Hi Frangois,
>
> Check out:
> http://www.dpawson.co.uk/xsl/sect2/N7450.html
>
> HTH,
> <prs/>
>
> -----Original Message-----
> From: Frangois Torche [mailto:torche@xxxxxxxxxx]
> Sent: Monday, December 20, 2004 11:21 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  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,
> Frangois
>
>


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



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

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.