Re: Preceding list function

Subject: Re: Preceding list function
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Fri, 4 Aug 2000 18:18:38 -0500
Quoting Norman Walsh <ndw@xxxxxxxxxx>:
> I just found a bug in the DocBook stylesheets and I don't see an easy
> way to fix it. But the structure of the error is such that I feel
> there ought to be an easy way. Can anyone see what I'm missing?
   Well, here's a possible solution (untested, mind you).  I know I
don't have your most recent stylesheets, so I'll just quote the
relevant function from the ones I have, with the parts that I changed

(define (orderedlist-listitem-number listitem)
  ;; return the number of listitem, taking continuation into account
  (let* ((orderedlist (parent listitem))
	 (listitems (select-elements (children orderedlist)
				     (normalize "listitem")))
	 (continue? (equal? (attribute-string (normalize "continuation")
			    (normalize "continues")))
	 ;; only look at lists in the same component
	 (preclist  (if continue?
			(let* ((lists (select-elements
;;;;					 orderedlist
					 (parent orderedlist)
;;;;					 (component-element-list)))
					  (list (normalize "orderedlist"))
				       (normalize "orderedlist"))))
			  (let loop ((nl lists) 
				     (prev (empty-node-list)))
			    (if (node-list-empty? nl)
				(if (node-list=?
				     (node-list-first nl)
				     (parent listitem))
				    (loop (node-list-rest nl)
;;;;					  (node-list-first nl))))))
					  (let ((nd (node-list-first nl))
					        (np (ancestor
					             (normalize "orderedlist")
					    (if (or (node-list-empty? np)
					            (not (node-list-contains?
						           lists np)))
	 (precitem (node-list-last (children preclist)))
	 (precitem-number (if continue?
			      (orderedlist-listitem-number precitem)
    (+ precitem-number (child-number listitem))))

   Now... the changes.  By adding orderedlist to the list of gis to
match in the call to ancestor-member, we can narrow our search to only
the other lists within the parent orderedlist, if there is one.  Of
course, we need to start with the parent of the current list, to avoid
matching the list we're in.
   The only other trick is to make sure the list we find is at the
same depth as the current list.  By keeping the search inside the
parent list (if there is one), we know that the current list will be
at the "top level" of the lists we're looking at, so we just need to
ensure that any list we consider does not have an ancestor list which
is also in the "list of lists" that we're traversing.
   If I haven't made this clear enough (likely, I suppose... it's been
a long day :P ), or if it doesn't actually work, let me know.

-Brandon :)

 DSSSList info and archive:

Current Thread