Home | Business News | Browse by Publication | X | XML Journal

Apply-templates revisited ...: how to design and use XSL templates.

Publication: XML Journal
Publication Date: 01-FEB-02
Format: Online
Delivery: Immediate Online Access
Full Article Title: Apply-templates revisited ...: how to design and use XSL templates.(Tutorial)

Article Excerpt
The beginning of every XSLT book or tutorial introduces "template matching" and how to use Apply-Templates. This article explains the benefits of using XSLT templates as well as some examples that show how a "real-world" application can use Apply-Templates along with other XSLT techniques.

Previously I've skirted around using Apply-Templates, opting instead for XSLT programming logic. The result was always a lot of XSLT code with , , and statements. Most of the "if" and "choose" statements checked the values or existence of nodes and elements in an XML file before parsing and displaying the output as HTML or XML. These applications required a lot of logic, and most continue to perform well, so maybe not using Apply-Templates was feasible, but in the future I intend to be more careful in designing applications that use stylesheets and how those stylesheets will be developed.

I recently ran into a situation where Apply-Templates should be used -- otherwise the XSL stylesheet would expand to over a hundred lines of unmanageable code. After piecing together a few examples from books and online, Apply-Templates is making everything much easier. I realize that thinking of templates as objects makes a lot of sense (to parse this node, use this object -- I mean template). Thinking this way produces a better design, which is explained more near the end of this article.

Two Types of Templates

Contrary to the introductory examples mentioned above, Apply-Templates is only part of the solution when building an application, and many XML/XSLT specifications are required in designing a larger application. The two basic concepts of XSLT are calling templates by name and applying templates.

* Calling templates: A fairly straightforward technique in which a template is named and then called to parse the selected data. When calling a template, parameters can be passed and these values can be used later to filter by or as another piece of information for the output.

* Applying templates: Relies on "matching" elements found in the data, then parsing each node -- actually performing two operations.

Applications that use both types are much easier to design than trying to make everything conform to one technique or the other.

Analyzing an XML Document

Understanding how an application needs to be developed and the structure of the XML document are the most important aspects of designing an XML-based program. Begin by looking for parts of the data that are unique. Alter analyzing a document, you can break the content or data into sections. Less

frequent data, such...

View this article FREE - Now for a Limited Time, try Goliath Business News
Free for 3 Days!



More articles from XML Journal
Building Web Services with Java: Making Sense of XML, SOAP, WSDL, and ..., February 01, 2002
Updated DocExpress adds XML links. (XML News).(Brief Article)(Product ..., February 01, 2002
Schema-based spec for business reporting finalized. (XML News).(Brief ..., February 01, 2002
BusinessObjects Developer Suite 5.5 unveiled. (XML News).(Brief Articl..., February 01, 2002
Sun introduces Java XML pack. (XML News).(Brief Article)(Product Annou..., February 01, 2002

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.