473,789 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1442


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:styleshe et
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:otherwis e>
<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***@wolterin kwebdesign.com> wrote in news:d8n7ga$emi $1
@netlx020.civ.u twente.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
4043
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 transformation file, so that if I have for example an XML record of <record> <elem1>fii</elem1> <elem2 />
5
454
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: public class SomeClass : IEmptyInterface or
39
4997
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
17116
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. This is okay in some cases (such as <tbody>), but problematic for other tags (such as <option>). Some tags (td, th, ...) do not produce warnings when they are empty.
2
1773
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 available. myiframe.InnerHTML often has leftover html which converts to nothing in the iframe (innertext), but is difficult to test for empty.
3
1880
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 oASP_Dgd_Receptions.Items Response.Write( CType( vDgi_GridItem.Cells(10).Text.trim.length ,
3
2579
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 instead of "nbsp;"), but I don't know how else to loop through each column in the current row: ========
0
2867
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" DataKeyNames="PersonId,RoleEntityGroup" DataSourceID="LDSPersonRoles"
1
1129
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. Unfortunately IE6 does not support the empty-cells css style. So Im looking for some way to allow me to display nothing without having to resort to &nbsp; which takes 6 characters. I could put a period of the same colour as the background, but...
0
9663
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, 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...
0
10193
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
10136
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
9016
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...
1
7525
isladogs
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...
0
5415
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...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4089
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
2906
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.