XSLT is a language designed to transform one XML document into another, changing both its schema and content in the process. At its most primitive, XSLT is a text-processing system that enables the programmer to transform XML documents, or, if required, generate other standard markup languages such as HTML (or any text, for that matter). In previous chapters, we have discussed the need for transformation as information moves between applications, so we will not devote our attention to it here. However, it is important to remember that XML documents are like messages. And because each application has its own unique set of application semantics, documents moving from application to application need to be transformed (see Figure 11.6). Both data structure and content must be semantically correct in order to load into the target application. If the data is not in the proper format, the update operation is likely to fail. Figure 11.6. You must transform XML as it moves from application to application.In addition to transforming the schema and content of XML documents, XSLT can perform other types of text-processing and transformation operations, which include creating text-based standard data formats such as comma-delimited files, PDFs, or other industry-standard formats that use text (see Figure 11.7). Figure 11.7. XSLT can also create other text-based formats, such as comma-delimited files and PDFs.
Before XSLT existed, most XML developers could only process incoming XML documents by creating custom applications that typically invoked one of two APIs: the Simple API for XML (SAX) and the Document Object Model (DOM). The SAX API was an event-based interface that used a mechanism through which the parser notified the application of each piece of information in the document as it was read. In the DOM API, the parser interrogated the document and created an object tree structure that represented the structure of the XML document in memory. From that point, a traditional program (e.g., C++ or Java) transformed the tree.
The limitation of both approaches was the same each time you wanted to transform a new XML document, you had to write a new program. XSLT provides several advantages over SAX and DOM. XSLT's design is based on the fact that most transformation programs use the same design patterns, and therefore can be automated using a higher-level, declarative language. (Stating that the XSLT language is declarative means that it describes the transformation behavior rather than a sequence of instructions necessary to perform the transformation. In other words, XSLT describes the transformation, then leverages the XSL processors to carry out the deed.) Moreover, when XSLT is used, the requirements of transformation can be expressed as a grouping of rules that define what output should be created when a particular pattern is encountered. |