473,804 Members | 2,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT Dynamic Table Column Headers and Rows

This may be a simple one but I have been working on it without joy for
a couple of days now. Reading books and searching these groups hasn't
helped yet either.

I am trying to create a table dynamically with column headers based on
the value of certain nodes and the rows populated ewith the values of
certain child nodes of the same parent.

My xml is something like this:

<docroot>
<target name="target1">
<types>
<type display_name="t ype1">
<type_mode>"som ething"</type_mode>
<typetype>"some thing"</typetype>
</type>
<type display_name="t ype2">
<type_mode>"som ething"</type_mode>
<typetype>"some thing"</typetype>
</type>
<type display_name="t ype3">
<type_mode>"som ething"</type_mode>
<typetype>"some thing"</typetype>
</type>
</types>
</target>
<target name="target2">
<items>
<item display_name="i tem1">
<item_mode>"som ething"</item_mode>
<itemitem>"some thing"</itemitem>
</item>
<item display_name="i tem2">
<item_mode>"som ething"</item_mode>
<itemitem>"some thing"</itemitem>
</item>
<item display_name="i tem3">
<item_mode>"som ething"</item_mode>
<itemitem>"some thing"</itemitem>
</item>
</items>
</target>
</docroot>
The table I am trying to generate will use the "name" attribute of each
"target" as the header for each column. The rows will be populated by
the value of each "item_mode" listed for that "target".

The goal is to list the information gathered for each target in columns
side by side to allow a visual comparison.

To complicate things a little further, the number of targets will vary
as will the number of "items" for each target.

Can anyone help with this at all?

Thanks a lot
CC

Jul 20 '05 #1
5 6793
Apologies, XML should read:

<docroot>
<target name="target1">
<items>
<item display_name="i tem1">
<item_mode>"som ething"</item_m*ode>
<itemitem>"some thing"</itemite*m>
</item>
<item display_name="i tem2">
<item_mode>"som ething"</item_m*ode>
<itemitem>"some thing"</itemite*m>
</item>
<item display_name="i tem3">
<item_mode>"som ething"</item_m*ode>
<itemitem>"some thing"</itemite*m>
</item>
</items>
</target>
<target name="target2">
<items>
<item display_name="i tem1">
<item_mode>"som ething"</item_m*ode>
<itemitem>"some thing"</itemite*m>
</item>
<item display_name="i tem2">
<item_mode>"som ething"</item_m*ode>
<itemitem>"some thing"</itemite*m>
</item>
<item display_name="i tem3">
<item_mode>"som ething"</item_m*ode>
<itemitem>"some thing"</itemite*m>
</item>
</items>
</target>
</docroot>

Jul 20 '05 #2

something like

<xsl:template match="docroot" >
<table>
<thead>
<tr>
<xsl:for-each select="target" >
<th><xsl:valu e-of select="@name"/></th>
</xsl:for-each>
</thead>
<tbody>
<xsl:for-each select="target[1]/items/item">
<tr>
<xsl:variable name="c" select="positio n()"/>
<xsl:for-each select="/docroot/target/items/item[$c]">
<td><xsl:valu e-of select="item_mo de"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
David
Jul 20 '05 #3
Thanks a lot David. Not only does it work, but makes sense to even me!

Jul 20 '05 #4
David wrote:

<xsl:template match="docroot" >
<table>
<thead>
<tr>
<xsl:for-each select="target" >
<th><xsl:valu e-of select="@name"/></th>
</xsl:for-each>
</thead>
<tbody>
<xsl:for-each select="target[1]/items/item">
<tr>
<xsl:variable name="c" select="positio n()"/>
<xsl:for-each select="/docroot/target/items/item[$c]">
<td><xsl:valu e-of select="item_mo de"/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>


This will work with the example XML, but I see two problems based on the
original criteria of multiple targets and multiple items per target.

1) If the first target has fewer item elements than any other target, then
the additional item elements will be skipped. You're going to need to
find the target with the maximum number of item elements.

2) If there are more than two target elements and any of the internal
(not first or last) ones have fewer item elements than the first, then the
subsequent <td> entries will collapse to the left and appear in the wrong
column.

Change:
<xsl:for-each select="/docroot/target/items/item[$c]">
<td><xsl:valu e-of select="item_mo de"/></td>
</xsl:for-each>
To:
<xsl:for-each select="/docroot/target">
<td><xsl:valu e-of select="items/item[$c]/item_mode"/></td>
</xsl:for-each>

This will insert a blank <td> into the table to maintain the column
integrity. If the <xsl:value-of> throws an error, then you'll need to use
an <xsl:if test="items/item[$c]"> around it.

Normand
Jul 20 '05 #5
Normand

Regarding your first point, I did some testing and you are right about
issues when the first target has fewer items. By jumping out into some
script (msxsl:script) I can determine which target has the most items.
What I can't do is use this information in building the table. Ideally
the order in which the targets are presented in the table will be the
same order they appear in the xml file.

Any ideas?

Thanks again

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5712
by: dschectman | last post by:
I have an interesting issue. I need to implement a dynamic table to mimic a select list. Each time you double click from the master list, a row is added to the list of selected items. The list of selected items has a column header and differentiation between odd and even rows. This part is trivial. Clients have the ability to re-order the list of selected items. This is also trivial: I trap the onClick event for a row to select it. ...
7
2459
by: Doug Heeren | last post by:
I have the following section of VB.NET code that transforms a simple dataset into an Excel xml workbook. It works fine for < 50 rows or so, but I have about 8,000 rows I need to transform. Is there a better way than what I am doing. This is part of an ASP.NET applicaiton. 'Clear the output stream Response.ClearHeaders() Response.ClearContent() Response.ContentType = "application/vnd.ms-excel" Response.Charset = ""
2
7405
by: Scamjunk | last post by:
I have been desperately looking for a treeview-type solution for my problem for the past three weeks and have been greatly unsuccessful. I am totally new to the world of XSLT and I *don't know* JavaScript. Still, I have managed to get something together, which I am putting across here. Any help (even pointing me to the place to look) is welcome. The problem I have is as follows:
0
3304
by: DAnne | last post by:
Hi, I'm very new to xslt and this is my first time posting to a Forum so please forgive me if I transgress any protocols. I have to do a tally report. This report is divided up into sections. Each section has a list of questions. Each question has responses. I need to display a list of responses to the questions (i.e. set:distinct), once and only once, each section. My second problem is that these questions can also have corrective...
0
5295
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all the days in the week with dates and textboxes to fill in some data. row 1: question
0
1466
by: miamikk | last post by:
I am XML newbie. I have question about inserting dynamic text in the header of HTML table. This is the site I have created (Only Report Type 1 is working) http://www.ustrade.fiu.edu/CustomsDistrict_Free.aspx The headers (Commodity Description, HS4, etc.) are static and I would like to add Month value in the Columns 3-6. Instead of "Year Amount($)", I would like to have the column header as "Month Year Amount ($)". Right now the "Year"...
7
12079
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
2
4365
by: djnokturnal | last post by:
Hey guys / gals, First time posting and of course I am sure it is something that has been answered 100 times but for some reason I just cant find the answer :) First off here is the structure of the xml: <Stats> <Structure> <Column DisplayName="GP" FieldName="GamesPlayed" Priority="1" /> <Column DisplayName="G" FieldName="Goals" Priority="2" />
5
4961
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums there are, it crashes. There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)? Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html Here is some jquery js that I think...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5508
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2978
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.