471,319 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Question about xslt:for-each

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.

Jul 27 '05 #1
2 1236
ge********@gmail.com:

//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>
<xsl:otherwise>
<!-- do something different here-->
</xsl:otherwise>
</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 :)
Jul 27 '05 #2
AWESOME. Worked like a charm. Thanks!

Jul 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Jeff Rubard | last post: by
4 posts views Thread by Gidi | last post: by
4 posts views Thread by David Waz... | last post: by
13 posts views Thread by Ghislain Tanguay | last post: by
4 posts views Thread by K8CPA | last post: by
14 posts views Thread by Jason.A.Oliver | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.