|
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
JSMITH@xxxxxxx
800-123-4567
901-123-4567
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
(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)))
**************************************************************************************
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
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.
*****
...Chuck Darney
...cdarney@xxxxxxxxxxxxxxxx
DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| DSSSL/XSL Training Course in Februa, G. Ken Holman | Thread | DD: Suggestions for Coherency, Ben Trafford |
| Re: DSSSL Documentation Project, Tony Graham | Date | Re: DSSSL Documentation Project, Paul Prescod |
| Month |