473,396 Members | 1,789 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,396 software developers and data experts.

Trying to put data into an alternating 2 column table.

Hello,

I have some xml data that look like:

<currencysummary rec_count="16">
<currency>
<currency_description>$</_currency_description>
<currency_code>1</_currency_code>
</currency>
<currency>
<currency_description>£</_currency_description>
<currency_code>2</_currency_code>
</currency>
<currency>
<currency_description>€</_currency_description>
<currency_code>3</_currency_code>
</currency>
<currency>
<currency_description>$</_currency_description>
<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="((currency_code mod 2) = 0)">
<td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_description"></xsl:value-of></td></tr>
</xsl:when>
<xsl:otherwise>
<tr><td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_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 1456
er**********@gmail.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**********@gmail.com wrote:
I have some xml data that look like:

<currencysummary rec_count="16">
<currency>
<currency_description>$</_currency_description>
<currency_code>1</_currency_code>
</currency>
<currency>
<currency_description>£</_currency_description>
<currency_code>2</_currency_code>
</currency>
<currency>
<currency_description>_</_currency_description>
<currency_code>3</_currency_code>
</currency>
<currency>
<currency_description>$</_currency_description>
<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:stylesheet
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="currencysummary"/>
</xsl:template>
<xsl:template match="currencysummary">
<table>
<xsl:apply-templates
select="currency[(position() mod 2)=1]"/>
</table>
</xsl:template>
<xsl:template match="currency[(position() mod 2)=1]">
<tr>
<td>
<xsl:value-of select="currency_code"/>
<xsl:value-of select="currency_description"/>
</td>
<xsl:apply-templates
select="following-sibling::currency[1]"/>
</tr>
</xsl:template>
<xsl:template match="currency[(position() mod 2)=0]">
<td>
<xsl:value-of select="currency_code"/>
<xsl:value-of select="currency_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**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Hello,

I have some xml data that look like:

<currencysummary rec_count="16">
<currency>
<currency_description>$</_currency_description>
<currency_code>1</_currency_code>
</currency>
<currency>
<currency_description>£</_currency_description>
<currency_code>2</_currency_code>
</currency>
<currency>
<currency_description>?</_currency_description>
<currency_code>3</_currency_code>
</currency>
<currency>
<currency_description>$</_currency_description>
<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="((currency_code mod 2) = 0)">
<td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_description"></xsl:value-of></td></tr>
</xsl:when>
<xsl:otherwise>
<tr><td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_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**********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.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
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...
4
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...
1
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...
47
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...
2
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. ...
1
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...
9
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...
1
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...
3
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...
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:
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.