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

Re: collapsing number ranges

Subject: Re: collapsing number ranges
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 30 Aug 2004 10:12:09 +0100
xsl leading zero
Hi Bruce,

>> I wouldn't have thought of using idiv and mod to get particular
>> digits if I hadn't seen David C.'s solution. I would have just used
>> substring() instead.
>
> Just out of curiosity, what are tradeoffs between the two
> approaches?

Well, you (and future maintainers of your code) might find the
substring() version less obscure.

There are type-related implications: some people would say that since
the values of $begin and $end are integers, you should process them as
integers rather than pretending that they're strings. The substring()
functions return a string whereas the mod/idiv operators return
numbers, and that can have an impact on whether you need to cast the
result or not, depending on what you're doing with it.

There's also a subtlety regarding the "get the last two digits". If
you have $begin = 108 then "$begin mod 100" returns the integer 8
whereas "substring($begin, string-length($begin) - 1)" returns the
string "08". So if you do a <xsl:value-of> then the substring()
version gives you a leading zero (which you can get rid of by casting
to a number with number()).

Also, if your $begin or $end actually *start* with a zero then the
mod/idiv versions will ignore them whereas the substring() function
will preserve them.

I doubt that there are significant performance differences.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

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.