|
Subject: Re: Desperate Questions: [1]Absolute-Child-Number From: Vivek Agrawala <vivek@xxxxxxxxxxxxxxx> Date: Tue, 24 Jun 1997 13:45:09 -0400 |
W. Eliot Kimber wrote:
> My first challenge is calculating the absolute child number of an element.
> The standard DTD has 7 different element types that are the first level
> divisions within standard (H1, scope, refs, defs, notation, annexn,
> annexi). In order to number things automatically I need the absolute child
> numbers of these element types. However, I can't for the life of me figure
> out how to do it. Here's my attempt at an absolute-child-number function:
>
> (define (absolute-child-number %element%)
> (- (node-list-length (children (parent %element%)))
> (length (member (node-list->list %element%) (node-list->list (children
> (parent %element%)))))))
>
How about something like this:
;; loop through the siblings of %element% till you find %element%
;; and return its position number
(define (absolute-child-number %element%)
(let loop ((siblings (children (parent %element%)))
(i 0) )
(cond
((node-list-contains? (node-list-first siblings) %element%) i)
((node-list-empty? siblings) -1) ;; error!
( else (loop (node-list-rest siblings) (+ i 1) ))))
Note that I just wrote this & haven't tested it!
-- Vivek Agrawala, Ph.D.
Siemens Corporate Research, Inc. email: vivek@xxxxxxxxxxxxxxx
DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: Desperate Questions: [1]Absolut, Paul Prescod | Thread | Re: Desperate Questions: [1]Absolut, Joe English |
| Re: Desperate Questions: [1]Absolut, Paul Prescod | Date | Re: Desperate Questions: [1]Absolut, W. Eliot Kimber |
| Month |