473,809 Members | 2,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Elements within elements

Hi,

I am trying to transform an XML file into a HTML table with XSLT. The
structure of my XML file is roughly this:

<profile>

<command name="..." phrase="...">
<key extended="..." pause="... repeat="..." duration="..."/>
...
<key extended="..." pause="... repeat="..." duration="..."/>
</command>

<command name="..." phrase="...">
<key extended="..." pause="... repeat="..." duration="..."/>
...
<key extended="..." pause="... repeat="..." duration="..."/>
</command>

...

</profile>

So, for every "command" element, there is one to many "key" elements. I
want to translate this structure to a simple HTML table that looks like

Command Key
Name Phrase Extended Pause Repeat Duration
-------------------------------------------------------------------
cmd1 cmd1 key1 key1 key1 key1
key2 key2 key2 key2
cmd2 cmd2 key1 key1 key1 key1
cmd3 cmd3 key1 key1 key1 key1
key2 key2 key2 key2
key3 key3 key3 key3
....
--------------------------------------------------------------------

(Tried to use TABs but am not sure whether the relative font will screw
up the structure of the table in my posting.)

Now handling command elements with only one key element inside is very
easy, as everything is put into a single row. My problem is how to handle
multiple key elements inside a command element, such that the data in the
subsequent key elements begins in its own row, from column 3.

There probably is a very obvious solution to this...
Jul 20 '05 #1
5 1367
Sorry, the structure of the intended table really WAS screwed up. Lets test
if this looks better:

-------------------------------------------------------------------
Command Key
Name Phrase Ext Pause Rpt Duration
-------------------------------------------------------------------
cmd1 cmd1 key1 key1 key1 key1
key2 key2 key2 key2
cmd2 cmd2 key1 key1 key1 key1
cmd3 cmd3 key1 key1 key1 key1
key2 key2 key2 key2
key3 key3 key3 key3
...
--------------------------------------------------------------------
Jul 20 '05 #2
Hi,

Jyrki Keisala wrote:

I am trying to transform an XML file into a HTML table with XSLT. The
structure of my XML file is roughly this:

<profile>

<command name="..." phrase="...">
<key extended="..." pause="... repeat="..." duration="..."/>
...
<key extended="..." pause="... repeat="..." duration="..."/>
</command>

<command name="..." phrase="...">
<key extended="..." pause="... repeat="..." duration="..."/>
...
<key extended="..." pause="... repeat="..." duration="..."/>
</command>

...

</profile>

[...]
Now handling command elements with only one key element inside is very
easy, as everything is put into a single row. My problem is how to handle
multiple key elements inside a command element, such that the data in the
subsequent key elements begins in its own row, from column 3.


I think you could use position() for this, e.g.

<xsl:template match="key">
<xsl:if test="position( )==1">
<!-- code for 1st row -->
</xsl:if>
<xsl:if test="position( )!=1">
<!-- code for all other rows -->
</xsl:if>
</xsl:template>

HTH,
Gerald
Jul 20 '05 #3
Given that you stated already that each command element must have at
least one key associated with it the best approach might be to
associate a template with the "command" element that also processes the
first "key" child line - further "key" element processing should be
done in a seperate template invoked with the appropriate predicate
(this avoids the expense of position checking on each invocation of the
key template). in sum:

<xsl:template match="command" >
<tr>
<td>...cmd elements...</td>
<td>...markup with ref to first key <xsl:value-of select="key[1]"
/></td>
</tr>
<!-- continue processing of subsequent keys -->
<xsl:apply-templates select="key[position() > 1]" />
<xsl:template >

<xsl:template match="key">
<tr>
<!-- insert some spacer elements for correct alignment ;) -->
<td>&nbsp;</td>
<!-- now process the key attributes + values -->
<td><xsl:valu e-of select="..etc.. ." /></td>
</tr>
<xsl:template >

hth
ajm.
Jyrki Keisala schrieb:
Sorry, the structure of the intended table really WAS screwed up. Lets test
if this looks better:

-------------------------------------------------------------------
Command Key
Name Phrase Ext Pause Rpt Duration
-------------------------------------------------------------------
cmd1 cmd1 key1 key1 key1 key1
key2 key2 key2 key2
cmd2 cmd2 key1 key1 key1 key1
cmd3 cmd3 key1 key1 key1 key1
key2 key2 key2 key2
key3 key3 key3 key3
...
--------------------------------------------------------------------


Jul 20 '05 #4
That solution certainly looks elegant, and I'll try it out. Thanks for
the tip!

Jyrki

Given that you stated already that each command element must have at
least one key associated with it the best approach might be to
associate a template with the "command" element that also processes
the first "key" child line - further "key" element processing should
be done in a seperate template invoked with the appropriate predicate
(this avoids the expense of position checking on each invocation of
the key template). in sum:

<xsl:template match="command" >
<tr>
<td>...cmd elements...</td>
<td>...markup with ref to first key <xsl:value-of select="key[1]"
/></td>
</tr>
<!-- continue processing of subsequent keys -->
<xsl:apply-templates select="key[position() > 1]" />
<xsl:template >

<xsl:template match="key">
<tr>
<!-- insert some spacer elements for correct alignment ;) -->
<td>&nbsp;</td>
<!-- now process the key attributes + values -->
<td><xsl:valu e-of select="..etc.. ." /></td>
</tr>
<xsl:template >

hth
ajm.

Jul 20 '05 #5
Jyrki Keisala <ji****@mail.su omi.net> wrote:
Hi,

I am trying to transform an XML file into a HTML table with XSLT. The
structure of my XML file is roughly this:

<profile>

<command name="..." phrase="...">
<key extended="..." pause="... repeat="..." duration="..."/>
...
<key extended="..." pause="... repeat="..." duration="..."/>
</command>

<command name="..." phrase="...">
<key extended="..." pause="... repeat="..." duration="..."/>
...
<key extended="..." pause="... repeat="..." duration="..."/>
</command>

...

</profile> Command Key
Name Phrase Extended Pause Repeat Duration
--------------------------------------------------------------------
cmd1 cmd1 key1 key1 key1 key1
key2 key2 key2 key2
cmd2 cmd2 key1 key1 key1 key1
cmd3 cmd3 key1 key1 key1 key1
key2 key2 key2 key2
key3 key3 key3 key3
...
-------------------------------------------------------------------


I would use XML parser included with an extended Bash shell.

start() {
case $1 in
command)
declare "${@:2}"
;;
key)
declare "${@:2}"
echo '<tr>'
printf '<td>%s</td>' "$name" "$phrase" "$extended" "$pause" "$repeat" "$duration"
echo '</tr>'
;;
esac
}
slurp=`< file.xml`
xml -s start "$slurp"

--
William Park <op**********@y ahoo.ca>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
http://home.eol.ca/~parkw/thinflash.html
Jul 20 '05 #6

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

Similar topics

9
8829
by: Stanimir Stamenkov | last post by:
Using Xerces2 Java I'm trying to validate a CSV data following an XNI example <http://xml.apache.org/xerces2-j/xni-config.html#examples>. The CSV scanner generates XML tree events like: <csv> <row> <col>Andy Clark</col> <col>16 Jan 1973</col> <col>Cincinnati</col>
13
40778
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div style="display:none"> can be displayed by setting the style attribute to "display:", or hidden with "display:none". This gives the illusion that the person filling out the form is switching from page to page...without the overhead of extra hits on the server,...
23
4097
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to <foo/>) From XHTML specification:
5
2246
by: Chris Reigrut | last post by:
I have a bunch of (old) pages that are outline-driven, and use the h1-h6 elements to define headings. Is there any way that I can create a stylesheet to show them in an indented style? For instance, my HTML is: &lt;html&gt; &lt;body&gt; &lt;h1&gt;Title Page&lt;/h1&gt; Some content, perhaps the intro. &lt;h2&gt;Section 1&lt;/h2&gt;
6
11993
by: Claude Schneegans | last post by:
Hi, In the code below, the lists elements at level 1 have a z-index of 1 and those at level 2 have it set to 2. Normaly, since level 1 and 2 overlap, level 2 elements should be seen above those at level 1; at least, this is what I'm trying to get. However, one can see ( http://www.contentbox.com/claude/test/zIndex.htm ) that the overlaping seems to correspond to the sequencial order of the elements, no matter
4
27934
by: Logico | last post by:
Hi everybody, I need to do a function in javascript to check or uncheck all checkboxes with the same id. I want this function to work in every form and every page of my site, as I will use the same id ("sel") for all checkboxes in the site. So I need to refer to these by id. I tried with: document.getElementById("sel") but this returns only the reference to the first element. Does anyone know how I can do?
13
371
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a base class for the worker class, and made up some functions/delegates to handle the invoke stuff for the UI and that was fine for a prototype. I rewrote this chunk, broke things out into different classes - but the threading is still the same - and...
4
1641
by: Daz | last post by:
Hello everyone. I have a simple problem which can be solved quite simply, I am just going about it the wrong way. I would like to wipe every row from within a named table, but I am not too sure how to do it. Each of these rows, are part of a JavaScript Object, which is bound to the table by objectName.bind('idOfTableToBindTo'). I have tried to destroy the objects themselves, but they still remain. Perhaps I am doing something wrong......
3
7584
by: =?Utf-8?B?TWFucHJlZXQgU3VzaGls?= | last post by:
I am having a Webservice within which i am throwing SOAP Exceptions and therefore whenever something wrong happens a SOAP fault comes up in the response - see below: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...
37
3684
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry over" when there are <br /tags involved...??? I've tried using <p style="font-weight: bold;"></p>, I've tried <blockquote></blockquote>...I just can't figure how I'm supposed to get the <b></btags to work for all the lines! Surely there must be...
0
9721
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
9600
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,...
0
10633
Oralloy
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...
0
10376
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
10375
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
9198
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...
0
5548
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...
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
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.