473,730 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please critique my solution: rendering HTML table using sparse data

Background: I'm collecting usability statistics for a group of
applications. Each count has the following attributes: date,
application, major heading, minor heading, count. My intent is
to pull this back as XML and render it in to an HTML table.

I have all this working and all the files are below. I would
value any feedback.

A simple example of the data looks like this:

<counts date="2004-10-07">
<application name="App A">
<major name="Major A">
<minor name="Minor A">1</minor>
<minor name="Minor C">7</minor>
<counts date="2004-10-08">
<application name="App A">
<major name="Major A">
<minor name="Minor A">1</minor>
<minor name="Minor B">3</minor>
<major name="Major B">
<minor name="Minor A">15</minor>

The output I am looking for is something like:

| | App A |
| +---------------------------------------+
| | Major A | Major B |
| +---------+---------+---------+---------+
| | Minor A | Minor B | Minor C | Minor A |
| 2004-10-07 | 1 | | | |
| 2004-10-07 | 1 | 3 | 7 | 15 |
| Totals | 2 | 3 | 7 | 15 |

Now I looked around for solutions that would let me tabularize
truely sparese data but didn't have any luck and no elegant
solutions came to mind.

The only solution I could come up with was to somehow massage the
data beforehand. The two choices I explored were

1) Turning it in to a non-sparse data set
2) Put a "domain" entry in front listing the union of all

I went with #2 (mainly because for real world data #1 would
inflate the size of the file significantly). So the final file
looks like:
<application name="App A">
<major name="Major A">
<minor name="Minor A"/>
<minor name="Minor B"/>
<minor name="Minor C"/>
<major name="Major B>
<minor name="Minor A"/>
<counts date="2004-10-07">
<application name="App A">
<major name="Major A">
<minor name="Minor A">1</minor>
<minor name="Minor C">7</minor>
<counts date="2004-10-08">
<application name="App A">
<major name="Major A">
<minor name="Minor A">1</minor>
<minor name="Minor B">3</minor>
<major name="Major B">
<minor name="Minor A">15</minor>

The XSLT I am using is at the end of this message. This is my
first non-trivial XSLT experiment so I would appreciate any
comments. A couple of specific questions:

1) I wanted to put &nbsp; in blank cells instead of "-". I
couldn't get the parsers to accept the &nbsp; (verbatim) in
the xslt file (line 60)

2) I used two templates for minor and non-minor table headers
because the colpan value was comming out to zero when (@line
27 & 34... referenced at 11, 12, and 13).

3) I access the actual data for each row by constructing a
path expression using each "minor" entry found in the
domain (line 55).

I would also value any stylistic comments.

Thanks in advance for any help

1: <?xml version="1.0" encoding="UTF-8"?>
2: <xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
3: <xsl:output method="html" version="1.0" encoding="UTF-8"
4: <xsl:template match="/counts-report">
5: <html>
6: <head>
7: <title>My Table</title>
8: </head>
9: <body>
10: <table border="1" cellpadding="5" >
11: <tr> <th rowspan="3">Dat e</th> <xsl:apply-templates
mode="header" select="domain/application"/> </tr>
12: <tr> <xsl:apply-templates mode="header"
select="domain/application/major"/> </tr>
13: <tr> <xsl:apply-templates mode="header"
select="domain/application/major/minor"/> </tr>
15: <xsl:apply-templates mode="data" select="counts"/>
17: <tr>
18: <th> Totals </th>
19: <xsl:apply-templates mode="totals"
20: </tr>
22: </table>
23: </body>
24: </html>
25: </xsl:template>
27: <xsl:template mode="header" match="*">
28: <xsl:element name="th">
29: <xsl:attribut e name="colspan"> <xsl:value-of
30: <xsl:value-of select="@name"/>
31: </xsl:element>
32: </xsl:template>
34: <xsl:template mode="header" match="minor">
35: <xsl:element name="th">
36: <xsl:value-of select="@name"/>
37: </xsl:element>
38: </xsl:template>
40: <xsl:template mode="data" match="counts">
41: <xsl:variable name="rownum" select="positio n()"/>
43: <xsl:element name="tr">
44: <xsl:if test="$rownum mod 2 = 0">
45: <xsl:attribut e name="style">ba ckground-color: rgb(0, 204,
46: </xsl:if>
48: <th> <xsl:value-of select="@date"/> </th>
50: <xsl:for-each
51: <xsl:variable name="app" select="../../@name"/>
52: <xsl:variable name="major" select="../@name"/>
53: <xsl:variable name="minor" select="@name"/>
55: <xsl:variable name="value"
57: <td>
58: <xsl:choose>
59: <xsl:when test="$value"> <xsl:value-of
select="$value"/> </xsl:when>
60: <xsl:otherwis e> - </xsl:otherwise>
61: </xsl:choose>
62: </td>
64: </xsl:for-each>
66: </xsl:element>
68: </xsl:template>
70: <xsl:template mode="totals" match="minor">
71: <xsl:param name="app" select="../../@name"/>
72: <xsl:param name="major" select="../@name"/>
73: <xsl:param name="minor" select="@name"/>
75: <td>
76: <xsl:value-of
77: </td>
78: </xsl:template>
80: </xsl:stylesheet>
Jul 20 '05 #1
3 2477

1) I wanted to put &nbsp; in blank cells instead of "-". I
couldn't get the parsers to accept the &nbsp; (verbatim) in
the xslt file (line 60)

This is the most FFF FAQ on xsl-list (which maintains a faq at

XML only predefines 5 entities (amp quot apos lt gt) so if you want to
use any other you need to redefine them in a DD and reference that DTD
in a doc type. In this case you don't need an entity at all you just
want to but a no break space into the result tree which is character 160
& # 1 6 0 ;
(without the spaces) if outputting html this will probably come out as
the entity nbsp but it may come out as character data (depending on your
processor) either way it will work in a browser.
You don't need to use xsl:element unless you are generating element
names dynamically so

<xsl:element name="th">
36: <xsl:value-of select="@name"/>
37: </xsl:element>

could more easily be written

36: <xsl:value-of select="@name"/>
37: </th>

almost certainly makes no difference to the processing speed or anything
else though, just easier to read.

Jul 20 '05 #2
cf******@yahoo. com (Sandros) wrote in
news:9c******** *************** ***@posting.goo gle.com:

1) I wanted to put &nbsp; in blank cells instead of "-". I
couldn't get the parsers to accept the &nbsp; (verbatim) in
the xslt file (line 60)

Replace &nbsp; with  

There are a couple of other solutions I prefer to use:

Create a transparent.gif image that is 1 pixel wide and 1 pixel high.

Whenever you need white space use it in an img tag with scaled height width

<img src="transparen t.gif" width="10" height="5" alt=" " border="0" />

Alternatively, use can use css styles:

<td style="backgrou nd-image: url(transparent .gif); background-repeat:repeat-
x;" width="20"></td>

Jul 20 '05 #3
Regarding style.

It's my opinion that xhtml should look as much as possible as html
and that the number of templates should be kept to a minimum.

Some of what you do as a template I'd recommend doing "in line".

That way if you can turn the project over to an html person.

It reads easier too. (Lines 11-14 look messy.)
Jul 20 '05 #4

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

Similar topics

by: Darryll Petrancuri | last post by:
Greetings! I could really use some suggestions on how to improve on the following, it at all possible: Table 'Customer' --------------------- ID GUID PK ....
by: g pavlov | last post by:
W3C recommendations notwithstanding (see http://w3.org/TR/html401/appendix/notes.html#notes-tables) I can't seem to persuade either of the leading browsers to do true incremental table loading. Neither responds to COL/COLGROUP tags. I have a very large data table which is being generated in J/ECMA/JavaScript dynamically. I want to give the user some top rows while the bottom rows are still loading. Without true incremental table...
by: TC | last post by:
Are there any good sites or forums for a web critique? I went to alt.html.critique and it's pretty dead.
by: bowsayge | last post by:
Inspired by fb, Bowsayge decided to write a decimal integer to binary string converter. Perhaps some of the experienced C programmers here can critique it. It allocates probably way too much memory, but it should certainly handle 64-bit cpus :) #include <stdio.h> #include <stdlib.h> char * to_binary (unsigned long value) {
by: christopher diggins | last post by:
I have posted a C# critique at http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up the following issues : - unsafe code - attributes - garbage collection - non-deterministic destructors - Objects can't exist on the stack - Type / Reference Types
by: Hazz | last post by:
I have been asked what I thought would be a good database design, data delivery mechanism and rendering method for an org chart with as many as 100,000 people. No other design specifications. 1. Database design? Good question. Employee Table EmployeeID EmployeeName ParentNode (BossID ??) Depth(some way to tell what depth the node is at)
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
by: Daniel T. | last post by:
The function below does exactly what I want it to (there is a main to test it as well.) However, I'm curious about ideas of making it better. Anyone interested in critiquing it? void formatText( const string& in, int charsPerLine, int lines, vector< string >& out ) { out.resize( 1 ); out = ""; int prev = 0;
by: Nik Coughlin | last post by:
I am halfway through writing a tutorial on image slicing for fluid CSS layouts, I would love some feedback on what I've done up until this point: http://nrkn.com/index.html I am still writing parts 3 & 4, "optimising the layout" and "alpha transparency". Also, does anyone know why I don't get numbers or bullets on my ul and ol in Internet Explorer (6 or 7)?
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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,...
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...
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...
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,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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
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.