Structure of This Book


To make this book useful to the broadest possible audience, I have retained most of the XSLT 1.0 solutions presented in the first edition. To these, I have added XSLT 2.0 solutions when 2.0 provided a significantly simpler or more elegant solution to the same problem. I also occasionally show 2.0 solutions to problems that would have been next to impossible to solve in 1.0. I have used separate subheadings to distinguish the 1.0 solution from the 2.0 solution. I hope this makes it easy for readers interested in one or the other to easily find what they are looking for. In a number of recipes, I do not provide a special 2.0 solution. Most of the time, this was because I felt the 1.0 solution would work as well in 2.0 or because I felt a 2.0 solution was obvious or would add very little value. I sincerely hope my desire to save trees and time does not overly frustrate the reader in this regard.

Both XSLT 1.0 and 2.0 rest firmly on the foundation provided by XPath 1.0 and 2.0, respectively. Some readers of the first edition took me to task for my lack of direct coverage of XPath. Chapter 1 was created partly to appease them and partly in response to the greater sophistication and complexity of XPath 2.0.

One of transformation's most primitive forms is its processing of character sequences otherwise known as strings. Unlike the ancient language SNOBOL or the relatively modern Perl, XSLT was not specifically designed with string manipulation in mind. However, Chapter 2 shows that almost anything one wants to do with strings can be done within the confines of XSLT and then shows how the new features of 2.0 make it that much easier.

Numerical transformation (commonly referred to as mathematics) is another crucial form of low-level transformation that pervades all software development simply because measurement and counting pervades life itself. Chapter 3 shows how to push the limits of XSLT's mathematical capabilities, even though XSLT was not designed to be the next great Fortran replacement.

Manipulating dates and times is a quintessentially human activity, and a large part of our technological progress has been driven by an obsession with clocks, calendars, and accurate forecasting. Chapter 4 contains date and time recipes that augment an area standard XSLT 1.0 currently lacks. It also has in-depth coverage of the most welcome date and time functions added to XSLT 2.0. This chapter presents fascinating and difficult problems arising in date conversion and transformation, ready-made XSLT solutions, and important links to external date- and calendar-related resources.

All transformations begin by identifying the target you want to transform. If that target is a compound object, you need to traverse the object's constituent parts as the transformation proceeds. Chapter 5 covers these topics and explores the problems XSLT was specifically designed to solve. This chapter describes XML as a tree and shows how XSLT can manipulate such trees. It also provides pointers for getting the best performance out of XML processing tasks.

Chapter 6 is brand new to the second edition and is dedicated entirely to XSLT 2.0. Readers who are primarily interested in getting up to speed in 2.0 are advised to read Chapters 1 and 6 first, and then peruse the rest of the XSLT 2.0 solutions sprinkled through the remaining chapters to gain a more solid foundation.

Before there were word processors, HTML, PDF, or other forms of sophisticated textual presentation, there was plain old text. The problem of transforming data used for computer consumption to data organized for human consumption is important. When the source data is XML, then the problem is perfect for XSLT. Chapter 7 provides recipes that control how text extracted from XML is rendered for layout on the terminal, on the text editor, or for import to programs that require delimited data, such as comma-separated values.

XML is quickly becoming the universal syntax for information transfer, and there is every indication that this trend will accelerate rather than abate. Therefore, a vast amount of XML transformation has XML as the destination as well as the source. Chapter 8 covers these types of transformations. It shows how XML documents can be split, merged, flattened, cleaned up, and otherwise reorganized with relatively little XSLT code.

Many transformations simply extract information from raw data to answer questions. Chapter 9 presents a treasure trove of recipes that demonstrate XSLT as a query language. It provides solutions to a wide variety of query-use cases that will probably resemble queries you'll need to ask of your own XML data.

HTML is an important target of XSLT transformation. Chapter 10 demonstrates solutions to problems that arise when generating web content, including links, tables, frames, forms, and other client-side transformation issues.

Graphics programming transforms data to the visual domain. You would not think of XSLT as a graphics programming language, and it is not. However, when Scalable Vector Graphics (SVG) is the target of the transformation, XSLT can achieve impressive results. Chapter 11 describes the transformation of raw data into bar charts, pie charts, line plots, and other graphical components. It also covers the transformation of XML to a hierarchical tree diagram. This chapter emphasizes how transformations are structures that can be mixed and matched to create many different outputs.

Generating code is an automation task that I have always been interested in. Of all the transformations, humans still do this one best (lucky for us who make a living at it). However, sometimes it is better to write a program that generates code rather than write the code ourselves. Chapter 12 shows the advantage gained from representing than the data that drives code generation in XML and illustrates how XSLT is ideal for writing code generators for C++, Java, and XSLT itself. The chapter also includes a code-generation recipe taken from a design pattern represented in UML via XMI.

XSLT can enable some sophisticated applications. Chapter 13 includes some advanced uses of XSLT. The chapter is an eclectic mix that includes Visio VDX to SVG conversion, Microsoft Excel XML transformation, topic maps, and WSDL processing.

Although XSLT is powerful in its own right, we can really do some wicked things with extensions or by embedding XSLT in programs written in other languages. Chapter 14 provides extensive coverage of XSLT extensibility using Java and Java-Script. It also shows how XSLT can be used within Perl and Java programs.

Testing and debugging are essential to any software development effort, and XSLT development is no exception. Chapter 15 demonstrates useful techniques that can help you transform misbehaved XSLT programs into functional ones, even if you don't have a native XSLT debugger handy.

Chapter 16 pushes the XSLT envelope to show how XSLT is far more than just another styling language. This chapter focuses on using XSLT as a generic and functional programming language. If nothing else, this chapter will open your eyes and stimulate your thoughts on the power of XSLT and how it can be used to create generic solutions.




XSLT Cookbook
XSLT Cookbook: Solutions and Examples for XML and XSLT Developers, 2nd Edition
ISBN: 0596009747
EAN: 2147483647
Year: 2003
Pages: 208
Authors: Sal Mangano

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net