In the DTD, an Organization Address consists of the following elements, all of them optional:
Who to contact in the organization. May contain multiple entries.
Name of the organization.
Division within the organization.
P.O. Box Number.
Street Address. Multiple lines allowed.
City
State
Country
Zip or other Postal Code
E-Mail address of contact or organization.
Phone number. Multiple entries alllowed.
FAX number
Example 1. 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
JSMITH@CWI.COM
800-123-4567
901-123-4567
901-123-4568 (FAX)
Example 2. DSSSL Code to Create the Formatted Address
(element ORGADDR
(let (
(orgcontact (select-elements (children (current-node))"ORGCONTACT"))
(orgname (select-elements (children (current-node))"ORGNAME"))
(orgdiv (select-elements (children (current-node))"ORGDIV"))
(postbox (select-elements (children (current-node))"POSTBOX"))
(street (select-elements (children (current-node))"STREET"))
(city (select-elements (children (current-node))"CITY"))
(state (select-elements (children (current-node))"STATE"))
(country (select-elements (children (current-node))"COUNTRY"))
(postcode (select-elements (children (current-node))"POSTCODE"))
(email (select-elements (children (current-node))"EMAIL"))
(phone (select-elements (children (current-node))"PHONE"))
(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)
(empty-sosofo)
(make sequence
(process-node-list city)
(literal ", ")
))
(if(node-list-empty? state)
(empty-sosofo)
(make sequence
(process-node-list state)
(literal " ")
))
(if(node-list-empty? country)
(empty-sosofo)
(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)
(empty-sosofo)
(make sequence
(process-node-list fax)
(literal " (FAX)")
)))
)
)
)
(element STREET
(make paragraph
(process-children)))
(element PHONE
(make paragraph
(process-children)))
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 value. 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 properly formatted.