|
Article Excerpt XSLT is a declarative language designed for transforming XML documents into documents in any format. In developing large-scale XSLT scripts, software qualities such as flexibility and maintainability become issues. To address those issues, this article will first discuss a design approach that emphasizes a decomposition and recomposition view of transformations; then, a technique for modularizing XSLT scripts will be described; and finally, a few design patterns will be introduced.
Identify Responsibilities and Assign Them to Code Units
The goal of any kind of application design is to divide responsibilities into smaller pieces and conquer them in separated code units. In XSLT, call-by-name templates, call-by-context templates, and global variables are code units, which are equivalent to functions in structured programming languages. Global variables are equivalent to call-by-name templates without any parameters. Call-by-context templates require callers and callees to share context information. Examples of three types of code units are shown in Listing 1.
LISTING 1 * Examples of three types of code units An example of call-by-name templates: The definition of a call-by-name template: The invocation of the call-by-name template: An example of call-by-context templates: The definition of a call-by-context template: The invocation of the call-by-context templates: An example of global variables: The definition of a global variable: The invocation of the global variable: $global-variable
Having identified code units in XSLT, we should study how to divide a complex transformation into smaller ones and assign each to a code unit.
At the most abstract level, due to the stateless nature of XSLT, the responsibility of any XSLT script can be described as transforming a set of input streams to an output stream. Intuitively, outputting a segment of the output stream can be the candidate of a smaller responsibility.
Outputting each line in Listing 2 could be a responsibility. However, abstraction is required to identify reusable and semantically significant segments. Identifying those segments, which may not even be continuous, requires insight into the output stream. It's easy for a C programmer to find outputting the conditional expressions a meaningful responsibility. The template that fulfills this responsibility is implemented in Listing 3.
LISTING 2 * The C++ code to output bool AClass::operator== ( const AClass & rhs ) const { if (intField1_!=rhs.intField1_) return false; if (intField2_!=rhs.intField2_) return false; if (strcmp (stringField_,rhs.stringField_) != 0) return false; return true; } LISTING 3 * The code unit outputting conditional expressions
Identifying smaller responsibilities is a decomposition process, which decomposes an output...
|
|

More articles from XML Journal
XML Schemas in an object-oriented framework: established best practice..., March 01, 2003 An introduction to BSML: enabling the bioinformatics revolution. (XML ..., March 01, 2003 XBRL for business reporting: positioned to become the global standard...., March 01, 2003 Microsoft BizTalk Server 2002 part 1: an out-of-box integration soluti..., March 01, 2003 Tamino XML server provides extended support. (XML News).(Brief Article..., March 01, 2003
Looking for additional articles?
Search our database of over 3 million articles.
Looking for more in-depth information on this industry?
Search our complete database of Industry & Market reports by text, subject, publication
name or publication date.
About Goliath
Whether you're looking for sales prospects, competitive information, company
analysis or best practices in managing your organization,
Goliath can help you meet your business needs.
Our extensive business information databases empower business
professionals with both the breadth and depth of credible,
authoritative information they need to support their business
goals. Whether it be strategic planning, sales prospecting,
company research or defining management best practices -
Goliath is your leading source for accurate information.
|
|