Question about xslt:for-each

G

gene.ellis

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.
 
S

Sorrow

(e-mail address 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>
<xsl:eek:therwise>
<!-- do something different here-->
</xsl:eek:therwise>
</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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top