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

RE: dynamic HTML table generation

Subject: RE: dynamic HTML table generation
From: "hudgins, tom" <hudgins_tom@xxxxxxx>
Date: Tue, 10 Oct 2000 08:32:27 -0400
dynamic html tables
I know this is a bit late and you may have already gotten a solution but
here is something I got from Corey Haines on another list that might do what
you want. After I slogged through it and got it working, I found it *very*
slow (due to all the recursion) and didn't continue using it. 

Here's the xml

<?xml version="1.0"?>
<tables>
	<table>
		<attributes>
			<table border="1" cellspacing="0" cellpadding="0"
width="80%"/>
			<tr align="center" style="background-color: Gray;
color: Blue;"/>
			<td width="33%"/>
		</attributes>
		<item row="2" col="2">2,2</item>
		<item row="5" col="3">5,3</item>
		<default>*</default>
	</table>
</tables>

And here's the xsl

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

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="//table">
	<xsl:call-template name="createtable">
	<xsl:with-param name="table" select="." />
	</xsl:call-template>
</xsl:for-each>
</body>
</html>
</xsl:template>

<xsl:template name="createtable">
<xsl:param name="table" />
<xsl:variable name='maxrows'>
	<xsl:call-template name="findmaxatt">
	<xsl:with-param name="list" select="$table/item" />
	<xsl:with-param name="tocomp">row</xsl:with-param>
	<xsl:with-param name="curval" select="'0'" />
	</xsl:call-template>
</xsl:variable>
<xsl:variable name='maxcols'>
	<xsl:call-template name="findmaxatt">
	<xsl:with-param name="list" select="$table/item" />
	<xsl:with-param name="tocomp">col</xsl:with-param>
	<xsl:with-param name="curval" select="'0'" />
	</xsl:call-template>
</xsl:variable>
<xsl:variable name='blanktable'>
	<table border='1'>
	<xsl:call-template name="createblanktable">
	<xsl:with-param name="numrows" select="$maxrows" />
	<xsl:with-param name="numcols" select="$maxcols" />
	</xsl:call-template>
	</table>
</xsl:variable>
<xsl:variable name='filledtable'>
	<table>
		<xsl:for-each select="$table/attributes/table/@*">
			<xsl:copy />
		</xsl:for-each>
		<xsl:for-each select="$blanktable/table/tr">
			<tr>
				<xsl:for-each
select="$table/attributes/tr/@*">
					<xsl:copy />
				</xsl:for-each>
				<xsl:for-each select="td">
					<td>
						<xsl:for-each
select="$table/attributes/td/@*">
							<xsl:copy />
						</xsl:for-each>
						<xsl:choose>
							<xsl:when
test="$table/item[@col = 1 + $maxcols - current()/@index and @row = 1 +
$maxrows - current()/../@index]">
	
<xsl:value-of select="$table/item[@col = 1 + $maxcols - current()/@index and
@row = 1 + $maxrows - current()/../@index]" />
							</xsl:when>
							<xsl:otherwise>
	
<xsl:value-of select="$table/default" />
							</xsl:otherwise>
						</xsl:choose>
					</td>
				</xsl:for-each>
			</tr>
		</xsl:for-each>
	</table>
</xsl:variable>
<xsl:copy-of select="$filledtable" />
</xsl:template>

<xsl:template name="createblanktable">
<xsl:param name="numrows" />
<xsl:param name="numcols" />
<xsl:if test="$numrows &gt; 0">
	<tr>
	<xsl:attribute name='index'><xsl:value-of select="$numrows"
/></xsl:attribute>
	<xsl:call-template name="makeblankrow">
	<xsl:with-param name="currow">1</xsl:with-param>
	<xsl:with-param name="numcols" select="$numcols" />
	</xsl:call-template>
	</tr>
	<xsl:call-template name='createblanktable'>
	<xsl:with-param name='numrows' select="$numrows - 1" />
	<xsl:with-param name="numcols" select="$numcols" />
	</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="makeblankrow">
<xsl:param name="numcols" />
<xsl:param name="currow" />
<xsl:if test="$numcols &gt; 0">
	<td><xsl:attribute name='index'><xsl:value-of select="$numcols"
/></xsl:attribute></td>
	<xsl:call-template name="makeblankrow">
	<xsl:with-param name="numcols" select="$numcols - 1" />
	<xsl:with-param name="currow" select="$currow" />
	</xsl:call-template>
</xsl:if>
</xsl:template>

<xsl:template name="findminatt">
<xsl:param name="list" />
<xsl:param name="tocomp" />
<xsl:param name="curval" />
<xsl:choose>
<xsl:when test="count($list) = 0">
	<xsl:value-of select="$curval" />
</xsl:when>
<xsl:otherwise>
	<xsl:variable name="compval">
		<xsl:value-of select="$list[1]/@*[name()=$tocomp]" />
	</xsl:variable>

	<xsl:variable name="newval" >
		<xsl:choose>
		<xsl:when test="$compval &lt; $curval">
			<xsl:value-of select="$compval" />
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$curval" />
		</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:call-template name="findminatt">
	<xsl:with-param name="list" select="$list[position() > 1]" />
	<xsl:with-param name="tocomp"><xsl:value-of select="$tocomp"
/></xsl:with-param>
	<xsl:with-param name="curval" select="$newval" />
	</xsl:call-template>

</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="findmaxatt">
<xsl:param name="list" />
<xsl:param name="tocomp" />
<xsl:param name="curval" />
<xsl:choose>
<xsl:when test="count($list) = 0">
	<xsl:value-of select="$curval" />
</xsl:when>
<xsl:otherwise>
	<xsl:variable name="compval">
		<xsl:value-of select="$list[1]/@*[name()=$tocomp]" />
	</xsl:variable>

	<xsl:variable name='newval'>
		<xsl:choose>
		<xsl:when test="$compval &gt; $curval">
			<xsl:value-of select="$compval" />
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$curval" />
		</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

	<xsl:call-template name="findmaxatt">
	<xsl:with-param name="list" select="$list[position() > 1]" />
	<xsl:with-param name="tocomp" select="$tocomp" />
	<xsl:with-param name="curval" select="$newval" />
	</xsl:call-template>

</xsl:otherwise>
</xsl:choose>
</xsl:template>
	
</xsl:stylesheet>

-----Original Message-----
From: Ireney Berezniak [mailto:iberezniak@xxxxxxx]
Sent: Thursday, October 05, 2000 3:18 PM
To: xsl-list@xxxxxxxxxxxxxxxx
Subject: dynamic HTML table generation


Hi,

I have a problem and so far I have been unsuccessful finding a solution.
Any
help you guys could provide would be greatly appreciated.

I need to format and create an HTML result set table dynamically. 
For example, in one instance I have a resultset in XML that contains 10
records.  I need to have an XSL file which generates a table with 2 rows and
5
columns.  In another instance, I might have a resultset that contains 20
records, and I need to present it in a 5 row by 4 column table using the
same
XSL file. I really want to do this dynamically. I can pass the desired row
and
column count into XSLT file so I know how many rows and columns I need to
create, but how do I do the looping to achieve this?

Thanks!

ib.

xml sample:
<rs:data>
	<z:row Product_Id="98652"/>
	<z:row Product_Id="98682"/>
	<z:row Product_Id="98718"/>
	<z:row Product_Id="104512"/>
	<z:row Product_Id="106564"/>
	<z:row Product_Id="174272"/>
	<z:row Product_Id="175242"/>
	<z:row Product_Id="191765"/>
	<z:row Product_Id="194131"/>
	<z:row Product_Id="194132"/>
</rs:data>

desired HTML table to be generated dynamically:
<TABLE>
	<TR>
		<TD></TD>
		<TD></TD>
		<TD></TD>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD></TD>
		<TD></TD>
		<TD></TD>
		<TD></TD>
		<TD></TD>
	</TR>
</TABLE>

or (depending on the rows/columns required)

<TABLE>
	<TR>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD></TD>
		<TD></TD>
	</TR>
	<TR>
		<TD></TD>
		<TD></TD>
	</TR>
</TABLE>


____________________________________________________________________
Get free email and a permanent address at http://www.amexmail.com/?A=1


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.