Re: (dsssl) node-lists

Subject: Re: (dsssl) node-lists
From: Brandon Ibach <bibach@xxxxxxxxxxxxxx>
Date: Mon, 9 Jul 2001 10:16:33 -0500
Quoting Patrice LaFlamme <ewd@xxxxxxxxxx>:
> I was wondering if there's any way to append nodes to a node-list?
> something like, I have an empty-node-list, and I want to append,
> say, a string or a number, then another, then another... 
> I guess what I want is an array ;)
   I think you may be confused about exactly what a node-list is.  A
node-list is an ordered collection of nodes from a grove (document).
It can only contain nodes, no strings or numbers.
   Now, if you're just looking for an "array", then a regular list
would serve your purpose.  There are several ways to create a list,
the simplest of which being:
	(list "abc" 123 ...)   (as many items as you want)
   If you also want nodes in your list, you can have node-lists as
items in your list.  DSSSL doesn't have a "node" type.  To represent a
single node, you just have a singleton node-list.
   Say you have a node-list "nl".  You could break it up into a list
of singleton node-lists with:
	(node-list->list nl)
You could also add other items onto this list:
	(append (node-list->list nl) (list "abc" 123))
   If your version of Jade/OpenJade doesn't have the (node-list->list)
function, you may need to add the following to your style-sheet:
	(define (node-list->list nl)
	   (reverse (node-list-reduce nl
	               (lambda (result snl) (cons snl result)) '())))
And if, by chance, it doesn't have (node-list-reduce):
	(define (node-list-reduce nl proc obj)
	   (if (node-list-empty? nl) obj
	       (node-list-reduce (node-list-rest nl) proc
	                         (proc obj (node-list-first nl)))))

-Brandon :)

 DSSSList info and archive:

Current Thread