[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] test for even or odd


Subject: Re: [xsl] test for even or odd
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 21 Jan 2005 18:17:34 -0500

Dear "xsl list", whoever-you-are,

You check oddness or evenness generally the same way you do in the particular case of alternating colors. If $count is your count of nodes, then

test="$count mod 2 = 1"
returns true for odd counts (when count is divided by 2, the remainder is 1)

test="$count mod 2 = 0"
returns true for even counts (when it's divided by 2 the remainder is 0)

Because of the number->Boolean casting rules (1 = true, 0 = false), if you say

test="$count mod 2"
it will test true for odd counts, false for even counts.

As Mike showed earlier today, the modulus operator (which returns remainders) can be used like this to determine any kind of regular cycling, not just odd-even.

Enjoy,
Wendell

At 05:47 PM 1/21/2005, you wrote:
So I have come down to this, I am going to get a count of how many
elements there are of a certain tag. How can I test if the number is
even or odd? Stateing the obvious here but if it came back with 3 of
the tag I would want a "this number is odd" returned (or 1 and 0 for
even).

I already have my rows alternating in color, but there are two sets, I
need to first check for directories and place them and then I check
for files and place them. When I check for files I then check to see
if there was a even or odd number of files telling me what color to
start on!

Thanks!


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


Current Thread
Keywords
xml