Jump to content

Dynamic table column creation


shadow_cloud_98

Recommended Posts

Hi, I am new (as in really new) to this forum and to xml (started reading up on it tuesday/wednesday). The reason for it is because i am trying to produce a printable report generated from an SQL database using ASP frontend that would look similar to the picture below : examplejp5.th.jpgAs shown in the example, there are 3 tables in the page - one for each heading. The most important part of this is that each table contains a right and left side. Basically, data taken from the database will display themselves in the table like so : left, right, left, right and so on. For example : if there are 11 records to be displayed under heading one, ideally 6 of these records would display on the left side of the page, and the other 5 on the right side of the page. In addition, if there are no records, heading two would then move up...There are a lot of examples on the net, but none that would actually allow the content of a column to wrap up back to the side of said column. Most tables examples would show one column, top down. Dynamic tables shows either a dynamically growing columns, or rows, but they are never of the 'wrapping' style. I have different suggestions on how i can go, primarily, 1. Microsoft reporting services (which involves a lot of line counters, 6 tables side by side, with my using stored procedures to flag recordset to display on the right and left tables, and some ways to trick the system so that headings will move to the next page if they are continued on the next page and so on). 2. Ajax (using draggable contents, i can allow the user to customize their own page - however printing it so that it would stay consistent (like pdf) poses a problem : I dont know what can or cant be done with ajax.3. XML - which i am also completely in the dark currently as to how i can create this sort of table, and how i can then allow the printing of the content. I am open to any suggestion right now as to how to produce a report such as the one i drew in paint. :). If it can be done in XML, it would be great if i can be shown link(s) to tutorials on how to achieve it. If it can only be done on the SQL pull, by marking the record as Left column and Right column content, then perhaps i might just stick with reporting services. ? Any help/suggestion is appreciated. Thank you!

Link to comment
Share on other sites

I didn't really read your post all the way through (haha...sorry), but hopefully this helps (I did this fast so sorry if there are errors or I completely did something unrelated)xml:

<thexml><node><heading>Title Here 1</heading><name age="22">My Name</name></node><node><heading>Title Here 2</heading><name age="18">First Last</name></node></thexml>

xsl:

<xsl:template match="thexml"><xsl:for-each select="node"><div id="yourboxdesignholder"><div id="yourheader><xsl:value-of select="heading"/></div><div id="innerbox"/><u><xsl:value-of select="@age"/> <xsl:value-of select="name"/></u></div></div></xsl:for-each></xsl:template>

Link to comment
Share on other sites

Exactly what is your XML structure? You'll be generating it from a database with ASP, correct? Well, I suggest this structure:

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="windows-1251"doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/><xsl:param name="group-size" select="4" /><xsl:template match="/db"><html xmlns="http://www.w3.org/1999/xhtml">	<head>		<title>Untitled Document</title>		<style type="text/css">			td {border: 1px solid #000000;}		</style>		</head>		<body>			<h1>Heading 1</h1>			<table>				<xsl:apply-templates select="person[(position() mod $group-size) = 1]">					<xsl:with-param name="mode" select="1"/>				</xsl:apply-templates>			</table>			<h1>Heading 2</h1>			<table>				<xsl:apply-templates select="person[(position() mod $group-size) = 1]">					<xsl:with-param name="mode" select="2"/>				</xsl:apply-templates>			</table>			<h1>Heading 3</h1>			<table>				<xsl:apply-templates select="person[(position() mod $group-size) = 1]">					<xsl:with-param name="mode" select="3"/>				</xsl:apply-templates>			</table>		</body> 	</html> </xsl:template><xsl:template match="person">	<xsl:param name="mode"/>	<tr> 		<xsl:for-each select=". | following-sibling::person[position() < $group-size]"> 			<td>				<xsl:choose>					<xsl:when test="$mode = 1">						<xsl:value-of select="age"/> - <xsl:value-of select="name"/>					</xsl:when>					<xsl:when test="$mode = 2">						<xsl:value-of select="adress"/> - <xsl:value-of select="city"/>					</xsl:when>					<xsl:when test="$mode = 3">						<xsl:value-of select="job"/> - <xsl:value-of select="company"/>					</xsl:when>				</xsl:choose>			</td> 		</xsl:for-each>	</tr> </xsl:template></xsl:stylesheet>

P.S. This can also be done with the "mode" attribute on templates, but since the only different thing is the value, I think using a parameter is just as good. "mode" is only ideal if there are differences around the whole template.

Link to comment
Share on other sites

Ack sorry! Posted late before going home from work on friday - and i completely forgot about this forum til today >_< . Thank you for the replies, and for the code snippets. I will see if i can understand it :) , a complete newbie in XML - was only guessing that XML can do what i needed to do. Will let you guys know if it helps or if i encounter any problem.

Link to comment
Share on other sites

Hi Boen, thanks for the help - I have managed to play around with it to more accurately describe the report i am trying to create ( i realize that little painted picture i created was pretty sad >_<)So currently i am at this point: XML:

<?xml version="1.0" encoding="ISO-8859-1"?><?xml-stylesheet type="text/xsl" href="Final.xsl"?><db><person><name>John Smith</name><age>30</age><city>New City</city><adress>John Smith's adress</adress><job>Professional</job><company>Sun</company></person><project><title>Plastic</title><cost>2 Million</cost></project><Additional><partners>Company 1</partners></Additional><person><name>Mary joe</name><age>20</age><city>Toronto</city><adress>Queen Street</adress><job>CEO</job><company>W3</company></person><project><title>Food industry</title><cost>2 Million</cost></project><Additional><partners>Company 2</partners></Additional><person><name>Jeremy Steward</name><age>55</age><city>Welland</city><adress>Dryad street</adress><job>Student</job><company>Micrososl</company></person><project><title>Singing</title><cost>3 Million</cost></project><Additional><partners>Company 3</partners></Additional><person><name>Jeff Nicholson</name><age>76</age><city>Florida</city><adress>King street</adress><job>Programmer</job><company>Diesney</company></person><project><title>Fishing</title><cost>4 Million</cost></project><Additional><partners>Company 4</partners></Additional><person><name>Douglas George</name><age>67</age><city>Jakarta</city><adress>King street</adress><job>Database Admin</job><company>Dreamworlds</company></person><project><title>Whaling</title><cost>5 Million</cost></project><Additional><partners>Company 5</partners></Additional><person><name>Flash Gordon</name><age>45</age><city>Welland</city><adress>King street</adress><job>XML educator</job><company>Sunworks Co.</company></person><project><title>Restaurants</title><cost>6 Million</cost></project><Additional><partners>Company 6</partners></Additional><person><name>Knight Rider</name><age>68</age><city>Kuala lumpur</city><adress>King street</adress><job>Gardener</job><company>Steelinc</company></person><project><title>Garbage</title><cost>7 Million</cost></project><Additional><partners>Company 7</partners></Additional><person><name>MacGyver</name><age>34</age><city>Welland</city><adress>King street</adress><job>Nurse</job><company>Circus di soleik</company></person><project><title>Housing</title><cost>2 Million</cost></project><Additional><partners>Company 8</partners></Additional><person><name>Dominic Deegan</name><age>26</age><city>Welland</city><adress>King street</adress><job>Chef</job><company>Yonekxs</company></person><project><title>Automotive</title><cost>4 Million</cost></project><Additional><partners>Company 9</partners></Additional><person><name>George Mcgrympy</name><age>44</age><city>Vancouver</city><adress>King street</adress><job>Governor</job><company>Carnation</company></person><project><title>Mining</title><cost>5 Million</cost></project><Additional><partners>Company 10</partners></Additional><person><name>Goofy Duck</name><age>45</age><city>Seattle</city><adress>King street</adress><job>President</job><company>Adobe</company></person><project><title>Debris</title><cost>5 Million</cost></project></db>

And XSL:

<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="windows-1251"doctype-public="-//W3C//DTD XHTML 1.1//EN" doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"/><xsl:param name="group-size" select="2" /><xsl:template match="/db"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Untitled Document</title><style type="text/css">td {border: 1px solid #000000;}</style></head><body><h1>Personnel</h1><table>	<xsl:apply-templates select="person[(position() mod $group-size) = 1]">		<xsl:with-param name="mode" select="1"/>	</xsl:apply-templates></table><h1>List of Partners</h1><table>	<xsl:apply-templates select="Additional[(position() mod $group-size) = 1]">		<xsl:with-param name="mode" select="3"/>	</xsl:apply-templates></table><h1>Project</h1><table>	<xsl:apply-templates select="project[(position() mod $group-size) = 1]">		<xsl:with-param name="mode" select="2"/>	</xsl:apply-templates></table></body></html></xsl:template><xsl:template match="person"><xsl:param name="mode"/><tr><xsl:for-each select=". | following-sibling::person[position() < $group-size]"><td><xsl:choose><xsl:when test="$mode = 1">name: <xsl:value-of select="name"/> <br/> age: <xsl:value-of select="age"/> <br/> occupation: <xsl:value-of select="job"/> <br/> company: <xsl:value-of select="company"/> <br/> address: <xsl:value-of select="adress"/></xsl:when></xsl:choose></td></xsl:for-each></tr></xsl:template><xsl:template match="project"><xsl:param name="mode"/><tr><xsl:for-each select=". | following-sibling::project[position() < $group-size]"><td><xsl:choose><xsl:when test="$mode = 2">Project name: <xsl:value-of select="title"/> <br/> Budget: <xsl:value-of select="cost"/> </xsl:when></xsl:choose></td></xsl:for-each></tr></xsl:template><xsl:template match="Additional"><xsl:param name="mode"/><tr><xsl:for-each select=". | following-sibling::Additional[position() < $group-size]"><td><xsl:choose><xsl:when test="$mode = 3">Partner name: <xsl:value-of select="partners"/> </xsl:when></xsl:choose></td></xsl:for-each></tr></xsl:template></xsl:stylesheet>

Now what i need to do is 1. Somehow, the second column of the personnel table, the list of partners table and the project table , has to be aligned. Can this be done? 2. In reality, i have more subheadings such as these (up to 7 subheadings), and i need to be able to somehow make them fit in the pages of the report they are in. For example, if subheading personnel and list of partners are so long that the subheading project has to be continued into the next page of the report, i will need to push that subheading completely to the next page. Is this possible? 3. For the purposes of making a report, i will need to somehow create a PDF document out of this. (or something similar..such as word document). Do i need a third party tool to do this, and will all the formatting i am doing currently in XML transfers over? 4. As you can see, my XML structure is a bit ...>_< wrong. I have no idea at this point on how to create a parent to the personnel, list of partners and projects. I did try to create a parent, and ended up with multiple tables for each individual. I know it is a simple command, but at this point it eludes me. Thank you in advance! :)

Link to comment
Share on other sites

Now what i need to do is 1. Somehow, the second column of the personnel table, the list of partners table and the project table , has to be aligned. Can this be done?
Ah...blame me a HTML/CSS noob as well. I finally figured out that i can manipulate the table attributes in the XSL stylesheet using the same html table attributes to specify column widths , cellspacing and aligns to try to align the different table's columns. One down :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...