473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to put data into an alternating 2 column table.

Hello,

I have some xml data that look like:

<currencysummar y rec_count="16">
<currency>
<currency_descr iption>$</_currency_descr iption>
<currency_code> 1</_currency_code>
</currency>
<currency>
<currency_descr iption>£</_currency_descr iption>
<currency_code> 2</_currency_code>
</currency>
<currency>
<currency_descr iption>€</_currency_descr iption>
<currency_code> 3</_currency_code>
</currency>
<currency>
<currency_descr iption>$</_currency_descr iption>
<currency_code> 4</_currency_code>
</currency>
</currencysummary >

I'd like to get it to look like:

<table cellpadding="2" cellspacing="0" border="0">
<tr><td>1$</td><td>2£</td></tr>
<tr><td>3€</td><td>4$</td></tr>
</table>

I've tried

<table cellpadding="2" cellspacing="0" border="0">
<xsl:for-each select="/page/contents/currencysummary/currency">
<xsl:choose>
<xsl:when test="((currenc y_code mod 2) = 0)">
<td><xsl:valu e-of
select="currenc y_code"></xsl:value-of><xsl:value-of
select="currenc y_description"> </xsl:value-of></td></tr>
</xsl:when>
<xsl:otherwis e>
<tr><td><xsl:va lue-of
select="currenc y_code"></xsl:value-of><xsl:value-of
select="currenc y_description"> </xsl:value-of></td>
</xsl:otherwise>
</tr>
</xsl:choose>
</xsl:for-each>
</table>

But the xml parser doesn't like it because I have incomplete <trtags.
I also tried doing a CDATA around the beginning and ending <trtags.
Does anyone know how to do this?

-Eric

Sep 20 '06 #1
5 1466
er**********@gm ail.com wrote:
But the xml parser doesn't like it because I have incomplete <trtags.
You can't work in terms of tags. Think in terms of elements. Generate an
element, and generate content nested within it.

See some of the examples at
http://www.dpawson.co.uk/xsl/sect2/N7450.html
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Sep 20 '06 #2

er**********@gm ail.com wrote:
I have some xml data that look like:

<currencysummar y rec_count="16">
<currency>
<currency_descr iption>$</_currency_descr iption>
<currency_code> 1</_currency_code>
</currency>
<currency>
<currency_descr iption>£</_currency_descr iption>
<currency_code> 2</_currency_code>
</currency>
<currency>
<currency_descr iption>_</_currency_descr iption>
<currency_code> 3</_currency_code>
</currency>
<currency>
<currency_descr iption>$</_currency_descr iption>
<currency_code> 4</_currency_code>
</currency>
</currencysummary >

I'd like to get it to look like:

<table cellpadding="2" cellspacing="0" border="0">
<tr><td>1$</td><td>2£</td></tr>
<tr><td>3_</td><td>4$</td></tr>
</table>
OT, but you should use styles instead of obsolete HTML
attributes.
I've tried
[XSLT]
But the xml parser doesn't like it because I have
incomplete <trtags. I also tried doing a CDATA around
the beginning and ending <trtags.
Does anyone know how to do this?
Try the following:

<?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="xml"
version="1.0"
encoding="UTF-8"/>
<xsl:template match="/">
<xsl:apply-templates select="currenc ysummary"/>
</xsl:template>
<xsl:template match="currency summary">
<table>
<xsl:apply-templates
select="currenc y[(position() mod 2)=1]"/>
</table>
</xsl:template>
<xsl:template match="currency[(position() mod 2)=1]">
<tr>
<td>
<xsl:value-of select="currenc y_code"/>
<xsl:value-of select="currenc y_description"/>
</td>
<xsl:apply-templates
select="followi ng-sibling::curren cy[1]"/>
</tr>
</xsl:template>
<xsl:template match="currency[(position() mod 2)=0]">
<td>
<xsl:value-of select="currenc y_code"/>
<xsl:value-of select="currenc y_description"/>
</td>
</xsl:template>
</xsl:stylesheet>

(Note that it outputs XML, not HTML -- tinker with
xsl:output to get what you need.)

--
Pavel Lepin

Sep 21 '06 #3
This is quite easy, in fact.

The following is an example how to create a table with N columns and display
every pair of rows in alternating colours:

http://www.topxml.com/code/default.a...20020514091249
Cheers,
Dimitre Novatchev
<er**********@g mail.comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...
Hello,

I have some xml data that look like:

<currencysummar y rec_count="16">
<currency>
<currency_descr iption>$</_currency_descr iption>
<currency_code> 1</_currency_code>
</currency>
<currency>
<currency_descr iption>£</_currency_descr iption>
<currency_code> 2</_currency_code>
</currency>
<currency>
<currency_descr iption>?</_currency_descr iption>
<currency_code> 3</_currency_code>
</currency>
<currency>
<currency_descr iption>$</_currency_descr iption>
<currency_code> 4</_currency_code>
</currency>
</currencysummary >

I'd like to get it to look like:

<table cellpadding="2" cellspacing="0" border="0">
<tr><td>1$</td><td>2£</td></tr>
<tr><td>3?</td><td>4$</td></tr>
</table>

I've tried

<table cellpadding="2" cellspacing="0" border="0">
<xsl:for-each select="/page/contents/currencysummary/currency">
<xsl:choose>
<xsl:when test="((currenc y_code mod 2) = 0)">
<td><xsl:valu e-of
select="currenc y_code"></xsl:value-of><xsl:value-of
select="currenc y_description"> </xsl:value-of></td></tr>
</xsl:when>
<xsl:otherwis e>
<tr><td><xsl:va lue-of
select="currenc y_code"></xsl:value-of><xsl:value-of
select="currenc y_description"> </xsl:value-of></td>
</xsl:otherwise>
</tr>
</xsl:choose>
</xsl:for-each>
</table>

But the xml parser doesn't like it because I have incomplete <trtags.
I also tried doing a CDATA around the beginning and ending <trtags.
Does anyone know how to do this?

-Eric
Sep 21 '06 #4

Dimitre Novatchev wrote:
This is quite easy, in fact.

The following is an example how to create a table with N columns and display
every pair of rows in alternating colours:

http://www.topxml.com/code/default.a...20020514091249
Cheers,
Dimitre Novatchev

I'm following this example and I'm seeing really bizarre behavior in
XML Spy. I save the xml to a file and the xsl to a file then assign
the xsl to the xml file. If I do a browser view in the XML window I
see alternative colored rows. If I run the debugger do a browser view
in the html code that's generated, I see one column. If I look at the
html that's generated it appears that the browser view of the html is
correct. Any idea what's going on?

-Eric

Sep 22 '06 #5

<er**********@g mail.comwrote in message
news:11******** *************@m 73g2000cwd.goog legroups.com...
>
Dimitre Novatchev wrote:
>This is quite easy, in fact.

The following is an example how to create a table with N columns and
display
every pair of rows in alternating colours:

http://www.topxml.com/code/default.a...20020514091249
Cheers,
Dimitre Novatchev


I'm following this example and I'm seeing really bizarre behavior in
XML Spy. I save the xml to a file and the xsl to a file then assign
the xsl to the xml file. If I do a browser view in the XML window I
see alternative colored rows. If I run the debugger do a browser view
in the html code that's generated, I see one column. If I look at the
html that's generated it appears that the browser view of the html is
correct. Any idea what's going on?

I guess this is a question to XML SPy's developers. I have never had any
problems using a compliant XSLT processor.

Cheers,
Dimitre Novatchev
Sep 23 '06 #6

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

Similar topics

2
1740
by: bettyann | last post by:
i am using templates via HTML_Template_IT to create a table from the results of a mysql query. i wanted to change the background image of alternating rows in the table. i thought i could do this by defining two different blocks in the template file and setting the current block based on ( $thisRowNum % 2 ). when the final table is displayed, all the "even" rows are displayed before all the "odd" rows. in other words, the rows are not...
4
1787
by: Mavis Tilden | last post by:
Hi all, So I've been reading the newsgroups, and reading a few books trying to learn SQL and SQL Server 2000. The books tell me I need a Primary Key, and that every table should have one. I know (I think) that a Primary Key is a special field that uniquely identifies each record or row within a table. My question is this: If I have a field or column whose values are all (and will be) different in every row, is that what a Primary Key...
1
4569
by: Alistair Birch | last post by:
Hi I want rows of a table to appear in alternating background colours. Having looked around the web I can't find any solution apart from waiting for the next version of CSS, so I tried building one myself, but I need some help to finish it. I use the getAttribute('rowIndex') to return the position of a row within the table and apply modulo 2 to return a 0 or 1 indicating an even or odd row number, from which I apply the alternating...
47
18876
by: Matt Kruse | last post by:
http://www.mattkruse.com/temp/css_expressions.html One of the standard CSS questions is "how can I shade every other table row a different color with CSS?" The answers are usually 1) you can't (yet), 2) put a class on every other tr, or 3) use javascript to do the styling for you. Well, I've been playing the CSS expressions quite a bit lately and I've found a much simpler solution which works in IE5.5+, using "expressions". If
2
1759
by: ecoulson123 | last post by:
I am using Access 2000. I am trying to summarize numeric data from a large database. The problem is that I need the summarization functions to ignore "junk" data, defined in a couple ways. Assume an excerpt of the database table looks like this: Lot SerialNumber Status Error 101 001 Good .3 002 Good .2 003 Mach Fail .4
1
1525
by: Henry | last post by:
I hope someone can help me on this. I have two controls on a form. the first is a comboBox the second is a datagrid. Both controls are bound to tables in a common dataset. What I am trying to get to happen is to have the value from the combobox control what populates the datagrid. I have two data adapters, the second of which uses a parameterized query to populate its referenced table in the dataset. I have two issues. first how to...
9
2686
by: Max Weebler | last post by:
Hi, I have a datagrid built that has an alternating item style that sets the backcolor and ForeColor of its rows. I have 4 template columns. One of them has a LinkButton embedded in it to perform updates. All the styles that are set are being followed by all templated columns with the exception for the update column. The update column does set the BackColor appropriately but when setting its ForeColor the LinkButton's color is blue and...
1
1310
by: Steve Bottoms | last post by:
Hi, all! How does one prevent table cell background colors from alternating between grey and white? I've dropped a basic table control on an ASP.Net page (using VB.Net codebehind), and dynamically creating rows and cells. However, I can't seem to get the blasted thing to stop alternating the background colors on every other row! I've tried setting the cell.BackColor property, but the value is just getting ignored! Also tried on...
3
3701
by: Daniel Manes | last post by:
My DataGridView is set up like this: * Main row background color = white * Alternating row background color = light gray I also have a read-only (non-editable) column I want to show up as solid dark gray (i.e., no alternating row colors), but it shows up as alternating dark/light gray. Is there any way to get around this?
0
8392
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
8305
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
8823
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
8726
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
8503
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
7320
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
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
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
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.