Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Trying to put data into an alternating 2 column table.

Reply
Thread Tools

Trying to put data into an alternating 2 column table.

 
 
eric.goforth@gmail.com
Guest
Posts: n/a
 
      09-20-2006
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>
<xsltherwise>
<tr><td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_description"></xsl:value-of></td>
</xsltherwise>
</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

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      09-20-2006
wrote:
> But the xml parser doesn't like it because I have incomplete <tr> tags.


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
 
Reply With Quote
 
 
 
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      09-21-2006

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 <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
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput
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
xslutput to get what you need.)

--
Pavel Lepin

 
Reply With Quote
 
Dimitre Novatchev
Guest
Posts: n/a
 
      09-21-2006
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


<> wrote in message
news: 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>
<xsltherwise>
<tr><td><xsl:value-of
select="currency_code"></xsl:value-of><xsl:value-of
select="currency_description"></xsl:value-of></td>
</xsltherwise>
</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


 
Reply With Quote
 
eric.goforth@gmail.com
Guest
Posts: n/a
 
      09-22-2006

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

 
Reply With Quote
 
Dimitre Novatchev
Guest
Posts: n/a
 
      09-23-2006

<> wrote in message
news: 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting & Fetching Data into a column of TEXT Data type in SQL server 2000 Using ASP.NET Bhavesh ASP .Net 0 07-16-2007 11:15 AM
GridView Footer - Put a link into the Edit / Delete column Remy ASP .Net 2 06-14-2006 05:51 PM
Alternating Item Style "ForeColor" not working in Template Column =?Utf-8?B?TWF4IFdlZWJsZXI=?= ASP .Net 9 10-27-2005 06:06 PM
Can we put ActiveX Control into the DataGrid Column? Vadim ASP .Net Datagrid Control 1 02-15-2005 03:55 PM
Activa or not activate a button column depending if another data column has data or not carlos perez ASP .Net 0 06-08-2004 02:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57