xsl-list
[Top] [All Lists]

RE: [xsl] One-based indexes in XPath

2008-05-20 10:05:35
Because the language was designed for users, not for programmers, and users
still have this old-fashioned habit of referring to the first chapter in a
book as Chapter One. (Though I did once hear Dijkstra refer to the fourth
slide in someone's presentation as the third.)

(I fully agree that when handling tables, or subscripting into strings,
zero-based addressing would often be much more convenient. There are
arguments both ways, and as always, I can't tell you what the actual history
of the decision was; I can only post-rationalize it.)

Michael Kay
http://www.saxonica.com/
 

-----Original Message-----
From: Justin Johansson [mailto:procode(_at_)adam(_dot_)com(_dot_)au] 
Sent: 20 May 2008 18:15
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] One-based indexes in XPath

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


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--