[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: test for even or odd

Subject: Re: test for even or odd
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 21 Jan 2005 18:17:34 -0500
test for even
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.