• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Formatting output with xsl:for-each question

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am iterating over my data with <xsl:for-each select="Colors">

My current code looks like so.

<xsl:for-each select="/Colors">
<tr>
<td>
<xsl:value-of select="."/>
</td>
<tr>
</xsl:for-each>

my output looks like

purple
red
orange
black
green
pink
brown
blue
yellow

I would like my output to look like this.

purple red orange
black green pink
brown blue yellow

Any pointers on how to accomplish this. Is there a way to load the data in
some type of array structure and loop over the data or a way to tell the <xsl:value-of select="."/> to move to the next piece of data?

Thanks
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pls try this out (havent tried out but think this would work)(pls take the condition value as per your requirement i.e. mod n - say mod 3)


[ April 28, 2005: Message edited by: Bajji Pat ]
 
Vic Newman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply but I am still encountering the same problem. The following code

<xsl:if position() mod n=0 or position()==last()></tr></xsl:if>

is not considered well formed because of the </tr> by itself.

Whenever I try and write html output in an if or when statement it has to be well formed. All <tr> must have matching </tr> in same statement of it will complain of not being well formed.

I am really missing the boat on something. All I am trying to do is build a row with 3 columns of data.

brown red purple
black green white

The input is coming in like
<color> brown </color>
<color> red </color>
<color> purple </color>
<color> black </color>
<color> green </color>
<color> white </color>


Vic
 
Bajji Pat
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vic,

Can the </tr> (or what ever elements cause well formedness check to fail)be enclosed within CDATA sections?? would that acheive desired result??

Balaji
 
Vic Newman
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to solve the problem. In order to get the data displayed as 3 per column, like

red brown black
green blue purple

I used the following code.

<xsl:for-each select=".|following-sibling::Color[1]|
following-sibling::Color[2]">


Thanks for the help!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic