Re: [xsl] One-based indexes in XPath

Subject: Re: [xsl] One-based indexes in XPath
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Tue, 20 May 2008 23:00:23 +0530
I don't know if I am right.

But I think 0 based indexes in low level languages (I consider Java or
C to be low level than XPath. Even I am talking about assembly
languages.) have relation to hardware addressing.

For e.g., a memory might have addresses ranging from 0000 to 1111
(this is just a small amount of memory). This probably has got to do
with logic of bits, where 0 has a very important meaning.

Lot of programming languages (also mentioned by you) have 0 based
indexes (in arrays, strings etc.), so compilers can easily map them to
hardware locations.

Indexes in XPath start from 1 because it's more convenient for the users.

On Tue, May 20, 2008 at 10:44 PM, Justin Johansson <procode@xxxxxxxxxxx> wrote:
> Trusting this question is relevant to the XSL List.
>
> Would someone please give me advice as to why "1-based" indexes are used in
> XPath, such as para[1] instead of para[0] for the first para item/element?
>
> Why does the spec for XPath (and its/XQuery operator/function library) go
> against the norm for modern programming languages in which zero is the base
> for array-like collections?
>
> The reason for my question is to do with reconciling XPath and XSLT with an
> implementation in Javascript in which zero is the base index for arrays.
> My users may well be perplexed by having to decide whether an index number
> is in XPath/XSLT-world or Javascript-world.
>
> Thanks for comments,
>
> Justin Johansson


-- 
Regards,
Mukul Gandhi

Current Thread