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.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn