Trying to put data into an alternating 2 column table.

E

eric.goforth

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:eek:therwise>
<tr><td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_description"></xsl:value-of></td>
</xsl:eek:therwise>
</tr>
</xsl:choose>
</xsl:for-each>
</table>

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

-Eric
 
P

p.lepin

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 <tr> tags. I also tried doing a CDATA around
the beginning and ending <tr> tags.
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:eek:utput
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:eek:utput to get what you need.)
 
D

Dimitre Novatchev

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.asp?p=3&id=v20020514091249


Cheers,
Dimitre Novatchev


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:eek:therwise>
<tr><td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_description"></xsl:value-of></td>
</xsl:eek:therwise>
</tr>
</xsl:choose>
</xsl:for-each>
</table>

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

-Eric
 
E

eric.goforth

Dimitre said:
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.asp?p=3&id=v20020514091249


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
 
D

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
 

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

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top