XSLT Cookbook, 2nd Edition

Book description

Forget those funky robot toys that were all the rage in the '80s, XSLT (Extensible Stylesheet Transformations) is the ultimate transformer. This powerful language is expert at transforming XML documents into PDF files, HTML documents, JPEG files--virtually anything your heart desires. As useful as XSLT is, though, most people have a difficult time learning its many peculiarities. And now Version 2.0, while elegant and powerful, has only added to the confusion.

XSLT Cookbook, Second Edition wants to set the record straight. It helps you sharpen your programming skills and overall understanding of XSLT through a collection of detailed recipes. Each recipe breaks down a specific problem into manageable chunks, giving you an easy-to-grasp roadmap for integrating XSLT with your data and applications. No other XSLT book around employs this practical problem-solution-discussion format.

In addition to offering code recipes for solving everyday problems with XSLT 1.0, this new edition shows you how to leverage the improvements found in XSLT 2.0, such as how to simplify the string manipulation and date/time conversion processes. The book also covers XPath 2.0, a critical companion standard, as well as topics ranging from basic transformations to complex sorting and linking. It even explores extension functions on a variety of different XSLT processors and shows ways to combine multiple documents using XSLT. Code examples add a real-world dimension to each technique.

Whether you're just starting out in XSLT or looking for advanced techniques, you'll find the level of information you need in XSLT Cookbook, Second Edition.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Structure of This Book
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari Enabled
    5. How to Contact Us
    6. Acknowledgments
  3. 1. XPath
    1. Introduction
    2. 1.1. Effectively Using Axes
    3. 1.2. Filtering Nodes
    4. 1.3. Working with Sequences
    5. 1.4. Shrinking Conditional Code with If Expressions
    6. 1.5. Eliminating Recursion with for Expressions
    7. 1.6. Taming Complex Logic Using Quantifiers
    8. 1.7. Using Set Operations
    9. 1.8. Using Node Comparisons
    10. 1.9. Coping with XPath 2.0’s Extended Type System
    11. 1.10. Exploiting XPath 2.0’s Extended Type System
  4. 2. Strings
    1. Introduction
    2. 2.1. Testing If a String Ends with Another String
    3. 2.2. Finding the Position of a Substring
    4. 2.3. Removing Specific Characters from a String
    5. 2.4. Finding Substrings from the End of a String
    6. 2.5. Duplicating a String N Times
    7. 2.6. Reversing a String
    8. 2.7. Replacing Text
    9. 2.8. Converting Case
    10. 2.9. Tokenizing a String
    11. 2.10. Making Do Without Regular Expressions
    12. 2.11. Exploiting Regular Expressions
    13. 2.12. Using the EXSLT String Extensions
  5. 3. Numbers and Math
    1. Introduction
    2. 3.1. Formatting Numbers
    3. 3.2. Rounding Numbers to a Specified Precision
    4. 3.3. Converting from Roman Numerals to Numbers
    5. 3.4. Converting from One Base to Another
    6. 3.5. Implementing Common Math Functions
    7. 3.6. Computing Sums and Products
    8. 3.7. Finding Minimums and Maximums
    9. 3.8. Computing Statistical Functions
    10. 3.9. Computing Combinatorial Functions
    11. 3.10. Testing Bits
  6. 4. Dates and Times
    1. Introduction
    2. 4.1. Calculating the Day of the Week
    3. 4.2. Determining the Last Day of the Month
    4. 4.3. Getting Names for Days and Months
    5. 4.4. Calculating Julian and Absolute Day Numbers from a Specified Date
    6. 4.5. Calculating the Week Number for aSpecified Date
    7. 4.6. Working with the Julian Calendar
    8. 4.7. Working with the ISO Calendar
    9. 4.8. Working with the Islamic Calendar
    10. 4.9. Working with the Hebrew Calendar
    11. 4.10. Formatting Dates and Times
    12. 4.11. Determining Secular and Religious Holidays
  7. 5. Selecting and Traversing
    1. Introduction
    2. 5.1. Ignoring Duplicate Elements
    3. 5.2. Selecting All but a Specific Element
    4. 5.3. Selecting Nodes by Context
    5. 5.4. Performing a Preorder Traversal
    6. 5.5. Performing a Postorder Traversal
    7. 5.6. Performing an In-Order Traversal
    8. 5.7. Performing a Level-Order Traversal
    9. 5.8. Processing Nodes by Position
  8. 6. Exploiting XSLT 2.0
    1. Introduction
    2. 6.1. Convert Simple Named Templates to XSLT Functions
    3. 6.2. Prefer for-each-group over Muenchian Method of Grouping
    4. 6.3. Modularizing and Modes
    5. 6.4. Using Types for Safety and Precision
    6. 6.5. Avoiding 1.0 to 2.0 Porting Pitfalls
    7. 6.6. Emulating Object-Oriented Reuse and Design Patterns
    8. 6.7. Processing Unstructured Text with Regular Expressions
    9. 6.8. Solving Difficult Serialization Problems with Character Maps
    10. 6.9. Outputting Multiple Documents
    11. 6.10. Handling String Literals Containing Quote Characters
    12. 6.11. Understanding the New Capabilities of Old XSLT 1.0 Features
  9. 7. XML to Text
    1. Introduction
    2. 7.1. Dealing with Whitespace
    3. 7.2. Exporting XML to Delimited Data
    4. 7.3. Creating a Columnar Report
    5. 7.4. Displaying a Hierarchy
    6. 7.5. Numbering Textual Output
    7. 7.6. Wrapping Text to a Specified Width and Alignment
  10. 8. XML to XML
    1. Introduction
    2. 8.1. Converting Attributes to Elements
    3. 8.2. Converting Elements to Attributes
    4. 8.3. Renaming Elements or Attributes
    5. 8.4. Merging Documents with Identical Schema
    6. 8.5. Merging Documents with Unlike Schema
    7. 8.6. Splitting Documents
    8. 8.7. Flattening an XML Hierarchy
    9. 8.8. Deepening an XML Hierarchy
    10. 8.9. Reorganizing an XML Hierarchy
  11. 9. Querying XML
    1. Introduction
    2. 9.1. Performing Set Operations on Node Sets
    3. 9.2. Performing Set Operations on Node Sets Using Value Semantics
    4. 9.3. Determining Set Equality by Value
    5. 9.4. Performing Structure-Preserving Queries
    6. 9.5. Joins
    7. 9.6. Implementing the W3C XML Query-UseCases in XSLT
  12. 10. XML to HTML
    1. Introduction
    2. 10.1. Using XSLT as a Styling Language
    3. 10.2. Creating Hyperlinked Documents
    4. 10.3. Creating HTML Tables
    5. 10.4. Creating Frames
    6. 10.5. Creating Data-Driven Stylesheets
    7. 10.6. Creating a Self-Contained HTML Transformation
    8. 10.7. Populating a Form
  13. 11. XML to SVG
    1. Introduction
    2. 11.1. Transforming an Existing Boilerplate SVG
    3. 11.2. Creating Reusable SVG Generation Utilities for Graphs and Charts
    4. 11.3. Creating a Tree Diagram
    5. 11.4. Creating Interactive SVG-Enabled Web Pages
  14. 12. Code Generation
    1. Introduction
    2. 12.1. Generating Constant Definitions
    3. 12.2. Generating Switching Code
    4. 12.3. Generating Message-Handling Stub Code
    5. 12.4. Generating Data Wrappers
    6. 12.5. Generating Pretty Printers
    7. 12.6. Generating a Test Data-Entry Web Client
    8. 12.7. Generating Test-Entry Web CGI
    9. 12.8. Generating Code from UML Models via XMI
    10. 12.9. Generating XSLT from XSLT
  15. 13. Vertical XSLT Application Recipes
    1. Introduction
    2. 13.1. Converting Visio VDX Documents to SVG
    3. 13.2. Working with Excel XML Spreadsheets
    4. 13.3. Generating XTM Topic Maps from UML Modelsvia XMI
    5. 13.4. Generating Web Sites from XTM Topic Maps
    6. 13.5. Serving SOAP Documentation from WSDL
  16. 14. Extending and Embedding XSLT
    1. Introduction
    2. 14.1. Saxon Extension Functions
    3. 14.2. Saxon Extension Elements
    4. 14.3. Xalan-Java 2 Extension Functions
    5. 14.4. Java Extension Function Using the Class Format Namespace
    6. 14.5. Java Extension Function Using the Package Format Namespace
    7. 14.6. Java Extension Function Using the Java Format Namespace
    8. 14.7. Scripting Extension Function Using Inline Script Code
    9. 14.8. Xalan-Java 2 Extension Elements
    10. 14.9. Java Extension Element
    11. 14.10. Scripting Extension Elements
    12. 14.11. MSXML Extension Functions
    13. 14.12. Using Saxon’s and Xalan’s Native Extensions
    14. 14.13. Extending XSLT with JavaScript
    15. 14.14. Adding Extension Functions Using Java
    16. 14.15. Adding Extension Elements Using Java
    17. 14.16. Using XSLT from Perl
    18. 14.17. Using XSLT from Java
  17. 15. Testing and Debugging
    1. Introduction
    2. 15.1. Using xsl:message Effectively
    3. 15.2. Tracing the Flow of Your Stylesheet Through Its Input Document
    4. 15.3. Automating the Insertion of Debug Output
    5. 15.4. Including Embedded Unit Test Data in Utility Stylesheets
    6. 15.5. Structuring Unit Tests
    7. 15.6. Testing Boundary and Error Conditions
  18. 16. Generic and Functional Programming
    1. Introduction
    2. 16.1. Creating Polymorphic XSLT
    3. 16.2. Creating Generic Element Aggregation Functions
    4. 16.3. Creating Generic Bounded Aggregation Functions
    5. 16.4. Creating Generic Mapping Functions
    6. 16.5. Creating Generic Node-Set Generators
  19. Index
  20. About the Author
  21. Colophon
  22. Copyright

Product information

  • Title: XSLT Cookbook, 2nd Edition
  • Author(s): Sal Mangano
  • Release date: December 2005
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596009748