Defaulting empty attributes to nbsp

J

Jyrki Keisala

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?
 
M

Martin Honnen

Jyrki said:
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:eek:utput 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:eek:therwise>
<xsl:text> </xsl:text>
</xsl:eek:therwise>
</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>
 
T

Tjerk Wolterink

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.
 
J

Jyrki Keisala

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top