[xsl] doubt regarding position() mod 2

Subject: [xsl] doubt regarding position() mod 2
From: "Anand Ganapathy" <Anand.Ganapathy@xxxxxx>
Date: Tue, 23 Apr 2002 12:45:02 +0530
Hello,
I have begun working on XSL recently.

I have written an XSL to convert my XML into an html which displays the xml as a tree.

My XML is as given below:
<?xml version="1.0" encoding="UTF-8"?>
<NODE1>
    <NODEADDRESS>1</NODEADDRESS> 
    <LEVELIDENTIFIER>1</LEVELIDENTIFIER> 
    <NODENAME>All Products                       </NODENAME> 
    <NODE2> 
        <NODEADDRESS>1:1</NODEADDRESS> 
        <LEVELIDENTIFIER>2</LEVELIDENTIFIER> 
        <NODENAME>Meat                               </NODENAME> 
            <NODE3> 
                <NODEADDRESS>1:1:1</NODEADDRESS> 
                <LEVELIDENTIFIER>3</LEVELIDENTIFIER> 
                <NODENAME>Eggs                               </NODENAME> 
            </NODE3> 
            <NODE3> 
                <NODEADDRESS>1:1:2</NODEADDRESS> 
                <LEVELIDENTIFIER>3</LEVELIDENTIFIER> 
                <NODENAME>Red Meat                           </NODENAME> 
            </NODE3> 
    </NODE2> 
    <NODE2> 
        <NODEADDRESS>1:2</NODEADDRESS> 
        <LEVELIDENTIFIER>2</LEVELIDENTIFIER> 
        <NODENAME>Dairy                              </NODENAME> 
    </NODE2> 
    <NODE2> 
        <NODEADDRESS>1:3</NODEADDRESS> 
        <LEVELIDENTIFIER>2</LEVELIDENTIFIER> 
         <NODENAME> Chocolate                          </NODENAME> 
    </NODE2> 
</NODE1> 

I need to display each alternating <NODENAME>element  under <NODE2> in a different color.
In my XSL, I tried using a test condition  <xsl:if test="position() mod 2 = 1">,
This test condition should return true for any item element that is an odd-numbered item child of its parent and hence 'Meat' and 'Chocolate' should be diplayed in the same color whereas 'Dairy' should be in a different color.
However, I am getting all these in the same color.Could you please  tell me where I am going wrong.Or is there a better way of achieving the same?

Anand.


 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread