Subject: copy-attributes+
From: "Maltby, David G" <david.g.maltby@xxxxxxxx>
Date: Fri, 21 Apr 2000 08:25:33 -0400
In a script I have been writing transforming instances from our authoring
DTD to our publishing DTD, I found I was forever wanting to get all the
attributes from an element copied to the transformed element plus a few more
derived from "the environment".  James' famous (copy-attributes) handles
arbitrary copies very well, great for maintainability when we add new
attributes to our author DTD. But after the copy there was no way to bolt on
my extra attributes.  The below procedure accomplishes both goals.

(element author
  (make element gi: "pub"
        attributes: (copy-attributes+ (list (list "new-name" "new-value")))

I am "tossing it over the wall" in case it might be valuable to others and,
since I still feel new to DSSSL, for peer (and I use that word as humbly as
I can) review.

;(copy-attributes+ extra-atts-list osnl)
;extra-atts-list: a list of lists, each of which consists of exactly two
;                 the first specifying the attribute name and the second the

;                 attribute value, which are to be added to a copy of the 
;                 attributes of osnl
;osnl:            optional singleton node list
;Requires (copy-attributes) []
;Returns a list of lists which consists of a copy of the attributes of osnl
;the passed in extra attributes
(define (copy-attributes+ extra-atts-list #!optional (osnl (current-node)))
  (let ( (copied-atts-list (copy-attributes osnl)) )		
    (if (not (list? extra-atts-list))
      (let loop ( (atts copied-atts-list) (ex-atts extra-atts-list) )
        (if (null? ex-atts)
          (if (not (list? (car ex-atts)))
            (loop atts (cdr ex-atts))
            (loop (cons (car ex-atts) atts) (cdr ex-atts))))))))

David Maltby, IETM Team, Lockheed Martin Space Systems
Cocoa Beach, FL

 DSSSList info and archive:

Current Thread