Sharing structured data

XML Magazine

Subscribe to XML Magazine: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get XML Magazine: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

XML Authors: Mamoon Yunus, Progress Blog, XebiaLabs Blog, Mat Rider, Sematext Blog

Related Topics: XML Magazine

XML: Article

Building a Flexible Presentation Framework

Building a Flexible Presentation Framework

Information interchange has become key to survival in an increasingly wired world. It is in this context that industries have adopted XML as the enabling mechanism to achieve application integration. XML is ideally suited for designing a Web application that has multiple pages, some of which display common business information.

If XML can be used to represent the application's business information, then XSL can be used to transform the XML for each of these pages. While Web designers can design the pages for the Web application, they can't be expected to design XSLT stylesheets. Stylesheet designers, on the other hand, are good at embedding transformation logic but are not conversant with writing HTML code or presentation tricks. This makes it hard to write XSLT stylesheets that transform the XML to HTML specific to each page. If Web designers can add special "tags" as placeholders for content, then those tags can be transformed at runtime using stylesheet rules.

This article will address performance, flexibility, and ease of maintenance in the context of a framework that combines the capabilities of Java servlets, XML, and XSLT to present business information as Web pages to an end user.

The Basics
XML is a subset of SGML. It was developed to provide features that are related to Web publishing environments.

XHTML is well-formed HTML. The loosely defined HTML specification can introduce interpretation problems to the browser and make it harder for HTML writers to validate the correctness of the HTML pages. Most browsers today attempt to interpret and render incorrect syntax in HTML pages, but sometimes the interpretation can be completely incorrect. This causes the rendered pages to be meaningless to the user. XHTML helps solve this problem since it requires HTML to be well formed. This means XHTML writers could validate their documents before publishing them. XHTML browsers can render XHTML documents correctly, eliminating the guesswork. Therefore, users can rely on the correctness of the document that is rendered by the browser.

XSLT is a high-level declarative language, intended for transforming XML documents into other XML documents. XSLT expressions are used to describe rules for transforming XML documents.

The Problem
Developing a Web application is a very challenging task that requires individuals of different skill levels. For example, a Web designer has organizational and artistic skills and uses design tools to design the layout for Web pages. But a Web designer doesn't necessarily have any technical skill, and may have little or no knowledge of HTML, which is the final product of the design. The Web designer may also lack the programming skills to develop an application that retrieves relevant data from data sources for use in Web pages. On the other hand, a Web application developer has programming skills. He or she knows how to write Web applications to retrieve relevant data from data sources.

Both the Web designer and the Web application developer have to coordinate through the entire development of a Web application, modifying the same set of Web pages, typically as HTML or JSP pages. Changes to the Web pages by one person usually affect the other. For example, if a Web page designer changes the layout of a Web page, he or she might accidentally delete the work done by a Web developer. Or, changes to a Web page by a Web developer might also accidentally cause changes to the layout. If these people don't work for the same company, sharing the same set of Web pages during development can pose a very difficult problem. Also, maintaining HTML Web pages is challenging, since HTML pages aren't easy to validate because well-formed HTML syntax is not guaranteed. Changes to HTML pages could potentially render them unusable or cause them to display differently on different browsers.

The Architecture
To solve these problems, we need to minimize the dependency between Web designers and Web application developers. We could allow the Web page designer to work on Web (XHTML) pages, and let the Web application developer work only on the application, with little or no dependency on the actual Web pages. This would tremendously increase the efficiency and productivity of both. Changes by either would have no impact on the other throughout the development of the Web application.

Requiring that the page be produced in XHTML instead of HTML can solve the maintenance problem of HTML pages. If Web pages are produced in XHTML, it can validate syntax correctness easily using various tools. This will guarantee that changes to Web pages do not render them unusable or cause them to be rendered differently by different browsers.

By introducing special tags to XHTML pages, the Web page designer can concentrate on design, without worrying about sharing Web pages with the Web application developer. These special tags are invented as a contract between Web page designer and Web application developer. At the beginning of and throughout the development of a Web application project, both the Web page designer and the Web application developer agree upon a set of special tags that the Web page designer needs for designing Web pages and the Web application developer needs to supply to the Web page designer. The Web page designer inserts these special tags into XHTML pages, where data supplied by the application program will be populated at runtime. The Web application developer references these special tags in the application code. A common XSLT stylesheet is developed to transform these special tags in the final process.

After Web page designs have been finalized, the Web designer and the Web application developer together define what data needs to be used and in which Web pages. Then, they define a set of data needed for each Web page. Along with the data for each Web page, names of all data are uniquely defined. The Web page designer uses special tag "fields" as placeholders for each type of data needed in a Web page. An attribute "name" of each "field" is used to uniquely define each data element in each Web page. (See bold lines in Listing 1, XHTML Web Page.)

The Web application developer develops a corresponding XML template for each XHTML Web page. (See bold lines in the example of a corresponding XML template, below.)

<field name="user.username"/>
<field name="user.password"/>

The Web application developer writes application code to retrieve data and references these field elements in the corresponding XML template. At runtime, requests from the browser to the Web application result in invocation of the corresponding piece of application code, which in turn retrieves the needed data and inserts it into the corresponding XML template. A simple XSLT rule is used to insert this XML template into the corresponding XHTML document. A final transformation using a common XSLT is used to transform this XHTML into an XHTML document that is understood by the browser. This final XHTML document is then returned to the browser.

Maintenance and isolation of the development of Web applications can be done quite easily. But XSLT is an interpreted process - every request results in interpreting an XML document, which can be a slow process. Having to interpret and transform XML documents for every request can incur high overhead to the Web application. Optimization is needed to minimize these overhead costs. Caching the XML template, XHTML document, and common XSLT stylesheet will reduce the overhead by eliminating the need for reconstruction for every request.

For easy and rapid Web application development, a tool can also be developed for the XML template and can generate the application code using information from the generated XML template to insert the data element into the XML template. This will reduce the requirement that the application developer has to know XML and XSLT and reduce development time because the application developer writes less code and, of course, there are fewer bugs to find and fix.

Of the many approaches that exist to develop a Web application, an approach to using standard XHTML and XML templates with a set of common XLST can reduce Web application development time and provide ease of maintenance for the Web application.


  • Ladd, Eric; O'Donnell, Jim; Morgan, Mike; and Watt, Andrew H. (2000). Using XHTML, XML and Java 2 Platinum Edition. Que.
  • Goldfarb, Charles F., and Prescod, Paul. (2001) Charles F. Goldfarb's XML Handbook, 4th Edition. Prentice Hall.
  • XSL Transformations (XSLT) Version 1.0. W3C Recommendation. November 16, 1999.
  • Extensible Markup Language (XML) 1.0 (Second Edition). W3C Recommendation. November 6, 2000.
  • XHTML 1.0 The Extensible HyperText Markup Language (Second Edition), A Reformulation of HTML 4 in XML 1.0. W3C Recommendation. January 26, 2000, revised August 1, 2002.
  • More Stories By Sawat Hansirisawat

    Sawat Hansirisawat is a senior software architect at Cysive, Inc., based in Reston, VA. Sawat has worked in the software industry for over 20 years and currently works in the product development group on the Cysive Cymbio Interaction Server. Sawat earned an MS degree in computer science from American University and holds a BS degree from Chulalongkorn University in Thailand.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.