473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Defaulting empty attributes to nbsp

I have an XML file which looks like this:

<command name="Options" phrase="Options">
<key value="z" extended="NONE" qual="L-CTRL" pause="100" repeat="1"
duration="200"/>
</command>

<command name="Command Room" phrase="Command Room">
<key extended="F2" pause="100" repeat="1" duration="200"/>
</command>

<command name="Attack Periscope" phrase="Attack Periscope">
<key extended="F3" pause="100" repeat="1" duration="200"/>
</command>

So, for each "key" element, there does not necessarily exist all attributes
(for example, for some, the attribute @value is missing).

I want to express this as a HTML table, so that for the missing attributes,
an empty &nbsp; cell is created. Any ideas, anyone?
Jul 20 '05 #1
3 1427


Jyrki Keisala wrote:
I have an XML file which looks like this:

<command name="Options" phrase="Options">
<key value="z" extended="NONE" qual="L-CTRL" pause="100" repeat="1"
duration="200"/>
</command>

<command name="Command Room" phrase="Command Room">
<key extended="F2" pause="100" repeat="1" duration="200"/>
</command>

<command name="Attack Periscope" phrase="Attack Periscope">
<key extended="F3" pause="100" repeat="1" duration="200"/>
</command>

So, for each "key" element, there does not necessarily exist all attributes
(for example, for some, the attribute @value is missing).

I want to express this as a HTML table, so that for the missing attributes,
an empty &nbsp; cell is created. Any ideas, anyone?

Here is an example how you could do it for the value attribute, you
would then need to add code for the other attributes as well:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="html" />

<xsl:template match="commands">
<table>
<tbody>
<xsl:apply-templates select="command" />
</tbody>
</table>
</xsl:template>

<xsl:template match="command">
<tr>
<xsl:apply-templates select="key" />
</tr>
</xsl:template>

<xsl:template match="key">
<td>
<xsl:choose>
<xsl:when test="@value">
<xsl:value-of select="@value" />
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:template>

</xsl:stylesheet>

Example result is

<table>
<tbody>
<tr>
<td>z</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
martin you are crazy,

let them find out for themselves how
xsl works. Or let them hire someone like you.

But you just give them the anwser!?
why? Why dont you use your time to create something
productive.
Jul 20 '05 #3
Tjerk Wolterink <tj***@wolterinkwebdesign.com> wrote in news:d8n7ga$emi$1
@netlx020.civ.utwente.nl:
martin you are crazy,

let them find out for themselves how
xsl works. Or let them hire someone like you.

But you just give them the anwser!?
why? Why dont you use your time to create something
productive.


Oh, thanks a lot for the constructive attitude, Tjerk. And what IS the
meaning of newsgroups such as this, if not among other things helping out
us who do not have as long experience with XSL as some others.

Believe it or not, I am not a 15-year old kid who wants all the answers
given straight away. I do experience with XSL quite a lot. It is just that
I do something else for my work and do not always have the time or
technical knowledge to work the answers out for myself. That is why I
sometimes (actually, very seldomly) turn to forums like this.

I think that the arrogance your posting shows does not do anything positive
to a very good newsgroup such as this.
Jul 20 '05 #4

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

Similar topics

4
by: Jyrki Keisala | last post by:
Hi, I have an XML file which I want to present as a HTML table, and I'm looking for a quick way of defaulting all empty elements in my XML file to a nbsp (using the   notation) in my XSL...
5
by: Doug Holland | last post by:
Often you see code where an empty interface is used to indicate something about the class that realizes it. In the .NET world this can be done with custom attributes too, so which is better: ...
39
by: fleemo17 | last post by:
I'm wondering whether it's better to leave an alt tag blank (alt=" ") or specify something like "alt='spacer'" when referring to objects that merely help the layout of the page? -Fleemo
12
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested....
2
by: Marcel Balcarek | last post by:
Hi, Is there a way in .NET to convert InnerHtml text e.g. '<B>hello</B>' to 'hello' ?? In IE I can use myiframe.innerText to know whether a field is empty, but in Netscape this method is not...
3
by: Simon Prince | last post by:
Hi, I'm trying detect an empty cell in a datagrid when the content is posted back to the server. My code is... Dim vDgi_GridItem As DataGridItem For Each vDgi_GridItem In...
3
by: Gilles Ganault | last post by:
Hello Some of the columns are empty, and must be turned into "nbsp;" so that an empty cell is shown when displayed in HTML. This code, however, doesn't work (meaning: I get an empty line...
0
by: Marius Manolea | last post by:
Hi, I have a strange problem, I don't receive any modifications from listview in edit mode (OldValues & NewValues are empty) <asp:ListView ID="lvEditPersonRoles" runat="server"...
1
by: Microsoft Newsserver | last post by:
I know this is not really an asp.net issue.But I know this is the home of the experts so I thought I would ask anyway. I am trying to reduce traffic and would prefer to have empty cells empty....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...

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.