Book description
Critical for converting XML documents, and extremely versatile, the XSLT language nevertheless has complexities that can be daunting. The XSLT Cookbook is a collection of hundreds of solutions to problems that Extensible Stylesheet Language Transformations (XSLT) developers regularly face. The recipes range from simple string-manipulation and mathematical processing to more complex topics like extending XSLT, testing and debugging XSLT stylesheets, and graphics creation with SVG. Recipes can be run directly or tweaked to fit your particular application's needs more precisely. Each recipe walks through a problem and a solution, with explanations of the choices made and techniques used in creating that solution, and many recipes include alternate solutions and explore issues like convenience and performance. Topics covered include:
String manipulation
Mathematical processing
Date and time handling
Interactions between calendar systems
Selecting content in source documents
Efficient tree-manipulation
Conversions from XML to plain text
Tweaking XML documents with stylesheets
Using XSLT to query XML documents
Generating HTML with XSLT
Creating charts and graphs with SVG and XSLT
Generating C and XSLT code using XSLT
Processing Visio documents in XSLT
Working with XML Topic Maps (XTM)
Using XSLT to create SOAP documentation from WSDL
Extending XSLT with additional functions
Embedding XSLT in other processing
Testing and debugging XSLT stylesheets
Creating generic XSLT processors which work on many XML vocabularies
The XSLT Cookbook provides an ideal companion both for developers still figuring out XSLT's template-based approach who want to learn by example, and for developers who know XSLT and want a collection of quickly reusable recipes. XSLT frequently offers a number of ways to perform a transformation, and the best solution may not always be the most straightforward. The recipes in this Cookbook demonstrate and explain XSLT's template-based logic, a frequent stumbling block for developers new to XSLT. Among the variety of XSLT books now available, none has the explicit solution-oriented approach of this Cookbook.
Table of contents
-
XSLT Cookbook
- Preface
-
1. Strings
- Testing if a String Ends with Another String
- Finding the Position of a Substring
- Removing Specific Characters from a String
- Finding Substrings from the End of a String
- Duplicating a String N Times
- Reversing a String
- Replacing Text
- Converting Case
- Tokenizing a String
- Making Do Without Regular Expressions
- Using the EXSLT String Extensions
-
2. Numbers and Math
- Formatting Numbers
- Rounding Numbers to a Specified Precision
- Converting from Roman Numerals to Numbers
- Converting from One Base to Another
- Implementing Common Math Functions
- Computing Sums and Products
- Finding Minimums and Maximums
- Computing Statistical Functions
- Computing Combinatorial Functions
- Testing Bits
-
3. Dates and Times
- Introduction
- Calculating the Day of the Week
- Determining the Last Day of the Month
- Getting Names for Days and Months
- Calculating Julian and Absolute Day Numbers from a Specified Date
- Calculating the Week Number for a Specified Date
- Working with the Julian Calendar
- Working with the ISO Calendar
- Working with the Islamic Calendar
- Working with the Hebrew Calendar
- Formatting Dates and Times
- Determining Secular and Religious Holidays
-
4. Selecting and Traversing
-
Optimizing Node Selections
- Problem
-
Solution
- Avoid unnecessary reliance on default processing rules
- Avoid using the descendant, descendant-or-self, preceding, or following axes when they aren’t necessary
- Prefer “selecting” and “matching” over “filtering”
- Cache frequently used node sets in variables
- Use xsl:key if nodes are frequently selected by static criteria
- Discussion
- Determining if Two Nodes Are the Same
- Ignoring Duplicate Elements
- Selecting All but a Specific Element
- Performing a Preorder Traversal
- Performing a Postorder Traversal
- Performing an In-Order Traversal
- Performing a Level-Order Traversal
- Processing Nodes by Position
-
Optimizing Node Selections
- 5. XML to Text
- 6. XML to XML
- 7. Querying XML
- 8. XML to HTML
- 9. XML to SVG
- 10. Code Generation
- 11. Vertical XSLT Application Recipes
-
12. Extending and Embedding XSLT
- Saxon Extension Functions
- Saxon Extension Elements
- Xalan Java 2 Extension Functions
- Java Extension Function Using the Class Format Namespace
- Java Extension Function Using the Package Format Namespace
- Java Extension Function Using the Java Format Namespace
- Scripting Extension Function Using Inline Script Code
- Xalan Java 2 Extension Elements
- Java Extension Element
- Scripting Extension Elements
- MSXML Extension Functions
-
Using Saxon’s and Xalan’s Native Extensions
- Problem
-
Solution
- You want to output to more than one destination
- You want to split a complex transformation into a series of transformations in a pipeline
- You want to work with dates and times
- You need a more efficient implementation of set operations
- You want extended information about a node in the source tree
- You want to interact with a relational database
- You want to dynamically evaluate an XPath expression created at runtime
- You want to change the value of a variable
- You want to write first-class extension functions in XSLT
- Discussion
- See Also
- Extending XSLT with JavaScript
- Adding Extension Functions Using Java
- Adding Extension Elements Using Java
- Using XSLT from Perl
- Using XSLT from Java
- 13. Testing and Debugging
- 14. Generic and Functional Programming
- Index
- Colophon
Product information
- Title: XSLT Cookbook
- Author(s):
- Release date: December 2002
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9780596003722
You might also like
book
XSLT Cookbook, 2nd Edition
Forget those funky robot toys that were all the rage in the '80s, XSLT (Extensible Stylesheet …
book
XSLT
XSLT documents a core technology for processing XML. Originally created for page layout, XSLT (Extensible Stylesheet …
book
Learning XSLT
XSLT is a powerful language for transforming XML documents into something else. That something else can …
book
XSLT for Dummies
Restructuring information in an XML document so that it works in other formats used to be …