Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

DOM example: address book software design

Tech Computer Center logo

At this point in time, the tools of choice for HTML presentation are either XSLT or a program using SAX or DOM.

The principle difficulty in using XSLT is the problem of getting the entries to appear at multiple places in the sequence. XSLT has a sort capability, but I can't see how to make it sort three different kinds of entities (organizations, individuals, and cross-reference terms) into a single sequence. This seems to me a clear indication of need for inheritance: three entities that share a sorting behavior, but present their content differently.

One approach I considered and discarded is to use a two-stage transform. In the first stage, transform the raw book into one that has the elements in presentation order---that is, transform each input <entry> into N new elements in the new tree, where N is the total number of <person>, <org>, and <xref> elements combined. For example, if an entry is for organization called Arkhamology, with people Smith and Green, and an <xref> for ``monoliths,'' the first-stage transform would add four entries, one each for keys Arkhamology, Smith, Green, and monoliths, but all having the same format. The second-stage transform would sort these entries by their common key and format them. But that seems like a rather perverse way to approach it.

So it seems to me that the clear choice is Python. Since an address book is not likely to be pathologically huge, we'll use the Document Object Model (DOM) to convert the entire document into a live tree in memory. Then we can build our own list containing objects representing the different types of entities, and use inheritance to give those different kinds of objects the same sorting behavior, so we can simply sort the list and then ravel the sorted objects out to HTML in order.

Important objects in the address.py module include:

In the addr-web.py script, important objects include:

The View class has two methods used to generate the two different renderings of the address book:


Next: DOM example: Web presentation
See also: Document Object Model example: address book
Previous: DOM example: address book requirements
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437
Home: About New Mexico Tech

John Shipman, john@nmt.edu
Last updated: 2002/11/14 21:22:52 UT
URL: http://www.nmt.edu/tcc/help/xml/addr-design.html
QR two-dimensional bar code