Well-structured XML Goes Cosmopolitan : Page 2

Everyone knows that among its many uses, XML can store the same data in multiple languages and dish it out like a U.N. translator when the computers of the world come calling. What everyone doesn't know is how best to structure that polyglot of data. There's more than one way

by Ilari Aarnio

Jun 4, 2003

Page 2 of 3

Language-oriented Structure
Listing 3 is the same resume example but this time structured in the language-oriented way.

This XML document in Listing 3 has a fundamentally different structure than the one in Listing 1. Listing 3 introduces a "language" element at the top level in the document structure. This splits the document into high-level sectionsone for each language the author intends to support. Each part uses an identical copy of the document structure, substituting the appropriate words for that language. Note also that the xml:lang attribute is used only within "language" elements. There is no need to scatter these attributes throughout the document.

Listing 4 is an XSL stylesheet for localized XHTML transformation.

Listing 4: Transforming the language-oriented structure for a multilingual resume.

The major difference between this stylesheet and the one in Listing 2 is in the first template, the one that processes the "cv" element. In Listing 4 the template selects the preferred language subtree and processes the elements of that subtree only. The rest of the templates do not need to worry about the current language because the choice has already been made. The stylesheet is therefore much more straightforward than the one in Listing 2.