Forum Moderators: open

Message Too Old, No Replies

XSLT to transform XML to HTML including table

How to handle empty cells?

         

chrisjoha

11:50 am on Aug 7, 2005 (gmt 0)

10+ Year Member



I need to tranform an XML to (X)HTML. There's basically alot of data that needs to be transformed into a table. I have two questoins for this. If all is well and all the data is present - no problems. BUT, if some cells are empty how do I handle that? I have something like this (structurally equal but simplified):

<item>
<description>Some item</description>
<price month="1">500</price>
<price month="2">300</price>
...
</item>
<item>
...
</item>
...


I want to transform it into this:

__________1___2___3___4___5___6___7
Some item 500 300 100 700 500 300 100

First problem: I plan on fetching the headers (months) from the first <item> - if this item lacks data for one month I won't get the header for that month and my table becomes incorrect - how do I handle that?
Second problem: If any given <item> lacks data for one or more months, how can I make sure an empty cell is displayed instead of moving the rest of the data on cell to the left?

Hope this was clear enough, and any help will be greatly appreciated!

chrisjoha

7:44 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



hmm, either my browser REALLY cached this page or this part of the forum ain't really that much alive ;)

choster

8:19 pm on Aug 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would help if we had a sample of your stylesheet code. Depending on how it is written, it could output an empty table cell or nothing at all.

athinktank

9:20 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



You are correct, this area gets little love.. and there is no moderator to boot!

There are so many ways that you can skin this cat. I would concur, post what you have, and we can take a look.

while we wait,
can you control the xml? add a <price month="9"></price> or <price month="9">0</price> for the null value entries? This would add some consistance in the xml that you are provided.

The other idea would be to assume that you want everymonth, all 12 of them displayed. Then you could *iterated* for 12 and display all the months. If, when tested, the month does not exist, then do the value does not exist algo.

But the code would really help...
Post the, if you have it, the xml, xsl, xsd(dtd), desired output example ext.