XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / Structure drives processing

(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 1.)

Whether and where a stylesheet should rely more on XSLT or XPath must be decided case by case. An XPath expression can be made arbitrarily clever, but this usually requires detailed knowledge of the source being processed. Such an optimized expression is almost inevitably error-prone when input structures vary, are unexpected or are even malformed.

When robustness is required, you are clearly in XSLT’s domain. (Note: Of course, XPath can also be written robustly, just as XML can be processed by programs written in PHP, Perl, C++ or Python.) Thus, a clever XPath expression could be replaced by a series of simple XSLT instructions, in the form of very simple template rules. However, quite a few would be needed: perhaps one or more for each element to be processed, since an element may need different processing in different contexts.

The basic idea is not to go and fetch information, which requires knowing where it is, but to use the source document itself as the processing plan. Processing follows the structure of the input document.

   

   

back to top