Re: Accessing declared value of attribute in Jade

Subject: Re: Accessing declared value of attribute in Jade
From: Daniel Speck <dspeck@xxxxxxxxxxxx>
Date: Tue, 07 Oct 1997 15:42:48 -0400
G. Ken Holman wrote:
> 
> At 16:41 97/10/06 -0400, Daniel Speck wrote:
> >I don't know how to access the attribute value token node. Can someone
> >give me a pointer?
> 
> I modified your data to add a test for the attribute not being present, and
> an attribute of the same name but not being of type ENTITY.
> 
> I then used the node-property function in order to determine that an
> attribute was of type ENTITY.  Note that this code fragment assumes only a
> single attribute and is not general enough to process all attributes or all
> kinds of attributes ... but it should be enough for you to add the
> detection of ENTITY to your own program.
> 
> Note how one must prepare for the access of a nodal property that does not
> exist.
> 
> I hope this helps.

Thanks Ken, this really helped (especially the bit about accessing a
nodal property that might not exist). The DSSSL standard is a bit light
on examples so  I often find myself thrashing about trying to find the
missing piece of the latest puzzle I am working on.

Here is the code that I finally came up with based on your example:

; (attribute-is-entity attnode)
;
; attnode is an attribute node (a node of class ATTASGN)
;
; (attribute-is-entity) returns the value of the ENTITY property if
non-empty,
; otherwise returns #f.
;
(define (attribute-is-entity attnode)
  (let ((attval (node-property "value" attnode 
			       default: (empty-node-list))))
    (if (node-list-empty? attval)
	#f
	(let ((attentity (node-property "entity" (node-list-first attval)
					default: (empty-node-list))))
	  (if (node-list-empty? attentity)
	      #f
	      attentity)))))

; (generate-data-entity-declaration entity-node)
;
; entity-node is a singleton node-list containing a node of class ENTITY
;
; (generate-data-entity-declaration) returns a string containing an SGML
; ENTITY declaration for the given entity.

(define (generate-data-entity-declaration entity-node)
  (let* ((entity-name (node-property "name" entity-node))
	 (entity-extid (node-property "external-id" entity-node))
	 (entity-sysid (node-property "system-id" entity-extid default: #f))
	 (entity-pubid (node-property "public-id" entity-extid default: #f))
	 (entity-notation (node-property "notation" entity-node))
	 (entity-notation-name (node-property 'name entity-notation))
	 )
    (string-append
     "&lt;!ENTITY " 
     entity-name 
     (if entity-pubid 
	 (string-append " PUBLIC \"" entity-pubid "\"")
	 "")
     (if entity-sysid 
	 (string-append " SYSTEM \"" entity-sysid "\"")
	 "")
     " NDATA " entity-notation-name
     ">&#RE;")))
 
-dan

-- 
Daniel Speck                              e-mail: dspeck@xxxxxxxxxxxx
Research Engineer                          voice:     +1 301.548.7818
Thomson Technology Services Group            fax:     +1 301.527.4094
1375 Piccard Drive, Rockville, MD 20850      WWW:    www.thomtech.com

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


Current Thread