Re: Desperate Questions: [1]Absolute-Child-Number

Subject: Re: Desperate Questions: [1]Absolute-Child-Number
From: Paul Prescod <papresco@xxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 24 Jun 1997 13:32:42 -0400 (EDT)
> 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.  

Does this just mean that you need the child number of %element% 's parent that 
is of one of those types? I'm not sure what you mean by "absolute" in this
context. Are you looking for smoething like

(child-number
   (ancestor-with-GI
       "H1" or "SCOPE" or "REFS" or "DEFS" or "NOTATION" or "ANNEXN"))

If so, you can write something like "ancestor-with-GI" like this:

(define (ancestor-with-GI gi-list #!optional (node (current-node)))
 (let ((orig-node node))
    (let internal ((node node) )
      (if (node-list-empty? node)
          #f
         (if (member (gi node) gi-list )
              node
             (internal (parent node)))))))

Caveat emptor: untested !!! I found this in some old code and adapted it...
It iterates over the parent nodes checking if they are in the list. When it
finds one in the list, it returns it. If it doesn't find one, it returns
false. Invoke it like this:

(ancestor-with-GI '(H1 SCOPE REFS DEFS NOTATION ANNEXN) (current-node))

 Paul Prescod


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread