aspose file tools*
The moose likes XML and Related Technologies and the fly likes Formatting output with xsl:for-each question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Formatting output with xsl:for-each question" Watch "Formatting output with xsl:for-each question" New topic
Author

Formatting output with xsl:for-each question

Vic Newman
Ranch Hand

Joined: Mar 01, 2002
Posts: 33
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
Bajji Pat
Ranch Hand

Joined: Apr 05, 2005
Posts: 50
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

Joined: Mar 01, 2002
Posts: 33
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

Joined: Apr 05, 2005
Posts: 50
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

Joined: Mar 01, 2002
Posts: 33
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Formatting output with xsl:for-each question