Formatting an Address - a solution

Subject: Formatting an Address - a solution
From: Chuck Darney <cdarney@xxxxxxxxxxxxxxxx>
Date: Tue, 20 Jan 1998 14:23:39 -0500
While it may not seem very difficult to some, it ceratinly helped me
with understanding a little about DSSSL.  Perhaps it will help someone
else as well.  Many thanks to Norm Walsh for his help in doing this!

Formatting an address for output.

In the DTD, an Organization Address consists of the following elements,
all of them optional:
	ORGCONTACT	Who to conact.  Multiple entries allowed
	ORGNAME		Name of the organization
	ORGDIV		Division
	POSTBOX		P.O. Box Number
	STREET		Street Address. Multiple Lines allowed.
	CITY		City
	STATE		State
	COUNTRY		Country
	POSTCODE	ZIP or other Postal Code
	EMAIL		E-Mail address of contact or organization
	PHONE		Phone Number.  Multiple entries allowed.
	FAX		FAX Number.

The output address should be formatted as:
	John Smith
	Cork Works, Inc.
	Accounting Department
	P.O. Box 1234
	Cork Oak Building
	726 Fine St.
	Virginia Beach, VA  US  23450
	901-123-4568  (FAX)

DSSSL  code:

(element ORGADDR
	(let	(	
		(orgcontact	(select-elements (children (current-node))"ORGCONTACT"))
		(orgname	(select-elements (children (current-node))"ORGNAME"))
              	(orgdiv		(select-elements (children
              	(postbox	(select-elements (children
              	(street		(select-elements (children
              	(city		(select-elements (children (current-node))"CITY"))
              	(state		(select-elements (children
              	(country 	(select-elements (children
              	(postcode	(select-elements (children
		(email		(select-elements (children (current-node))"EMAIL"))
             	(phone 		(select-elements (children
              	(fax		(select-elements (children (current-node))"FAX"))
        	(make sequence
        		(make paragraph
				(process-node-list orgcontact))
        		(make paragraph
				(process-node-list orgname))
        		(make paragraph
				(process-node-list orgdiv))
        		(make paragraph
				(process-node-list postbox))
        		(make paragraph
				(process-node-list street))
			(make paragraph
				(if(node-list-empty? city)
					(make sequence
						(process-node-list city)
						(literal ", ")
				(if(node-list-empty? state)
					(make sequence
						(process-node-list state)
						(literal "  ")
				(if(node-list-empty? country)
					(make sequence
						(process-node-list country)
						(literal "  ")
				(process-node-list postcode))
       			(make paragraph
				(process-node-list email))
       			(make paragraph
				(process-node-list phone))
       			(make paragraph
				(if(node-list-empty? fax)
					(make sequence
						(process-node-list fax)
						(literal "  (FAX)")

(element STREET
	(make paragraph
(element PHONE
	(make paragraph


What it's doing:
  The "select-element" statements are creating local variables that
correspond to 
all of the elements in the DTD. This appends the element values from the
DTD into a
single local variable.

  The "make sequence" specifies the order of output.

  The "if(node-list-empty?" statements test to see if the variable has a
If it does, it'll use it and add the literal text after it.  Otherwise
it continues.
If this weren't done, the literal text would appear even without the
variable. (if no 
"city" exists, there would be just a comma)  This is only necessary for
variables that
have a literal attached to them.

  The additional "element" statements make it possible to express
multiple DTD
element entries on separate lines.  In this case, multiple PHONES would
be appended
(800-123-4567908-123-4567) on a single line.  The "make paragraph"
statements put 
the numbers on separate lines.

  Unused elements from the DTD are not a problem.  The address remains

...Chuck Darney

 DSSSList info and archive:

Current Thread
  • Formatting an Address - a solution
    • Chuck Darney - from mail1.ability.netby (8.8.5/8.6.12) with ESMTP id OAA09277Tue, 20 Jan 1998 14:26:57 -0500 (EST) <=