xsl-list
[Top] [All Lists]

Re: test for even or odd

2005-01-21 16:17:34
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!

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>