Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Question about xslt:for-each

Reply
Thread Tools

Question about xslt:for-each

 
 
gene.ellis@gmail.com
Guest
Posts: n/a
 
      07-27-2005
Hello everyone. I have a pretty straight forward question:

I have some data stored in an XMl document in the format of:

<comment_info>
<comments>These are the comments</comments>
<comment_heading>This is comment heading</comment_heading>
</comment_info>

<comment_info>
<comments>These are the more comments</comments>
<comment_heading>This is another comment heading</comment_heading>
</comment_info>

and I am using an xslt:for-each command to create an .html page. I am
putting each comment_info section into it's own table on the .html
page. My question is how would I alternate table background colors of
these tables? For example I would want the 1,3,5... tables to have a
certain background color and the 2,4,6... tables to have another
background color. Is there some sort of function I can use to determine
if the comment_info block being returned is even or odd? I was even
thinking of placing the background color into the xml document itself,
but I would still need to know which background color I should insert
(again, is the comment_info block even or odd). I welcome any ideas.
Thank you.

 
Reply With Quote
 
 
 
 
Sorrow
Guest
Posts: n/a
 
      07-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed):

//snip
> My question is how would I alternate table background colors of
> these tables? For example I would want the 1,3,5... tables to have a
> certain background color and the 2,4,6... tables to have another
> background color. Is there some sort of function I can use to determine
> if the comment_info block being returned is even or odd?

//snip

Use XPath function position() and operator "mod" to check division
remainder:

<xsl:for-each select="select-statement">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<!--do something here-->
</xsl:when>
<xsltherwise>
<!-- do something different here-->
</xsltherwise>
</xsl:choose>
</xsl:for-each>

This solution actually gives you the possibility to use any nmber of
colours.
To sort nodes use <xsl:sort>.

Hope this was helpful.

Best regards,
Sorrow.

PS. This is my first post to this group, so a great welcome to you all. I
hope I'll learn much here


 
Reply With Quote
 
 
 
 
gene.ellis@gmail.com
Guest
Posts: n/a
 
      07-29-2005
AWESOME. Worked like a charm. Thanks!

 
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
question row filter (more of sql query question) =?Utf-8?B?YW5kcmV3MDA3?= ASP .Net 2 10-06-2005 01:07 PM
Quick Question - Newby Question =?Utf-8?B?UnlhbiBTbWl0aA==?= ASP .Net 4 02-16-2005 11:59 AM
Question on Transcender Question :-) eddiec MCSE 6 05-20-2004 06:59 AM
Question re: features of the 831 router (also a 924 question) Wayne Cisco 0 03-02-2004 07:57 PM
Syntax Question - Novice Question sean ASP .Net 1 10-20-2003 12:18 PM



Advertisments