Learning XSLT

Book description

XSLT is a powerful language for transforming XML documents into something else. That something else can be an HTML document, another XML document, a Portable Document Format (PDF) file, a Scalable Vector Graphics (SVG) file, a Virtual Reality Modeling Language (VRML) file, Java code, or a number of other things. You write an XSLT stylesheet to define the rules for transforming an XML document, and the XSLT processor does the work.As useful as XSLT is, its peculiar characteristics make it a difficult language in which to get started. In fact, newcomers are often a little dazed on first contact. Learning XSLT offers a hands-on introduction to help them get up to speed with XSLT quickly. The book will help web developers and designers understand this powerful but often mystifying template-driven and functional-styled language, getting them over the many differences between XSLT and the more conventional programming languages.Learning XSLT moves smoothly from the simple to complex, illustrating all aspects of XSLT 1.0 through step-by-step examples that you'll practice as you work through the book. Thorough in its coverage of the language, the book makes few assumptions about what you may already know. You'll learn about XSLT's template-based syntax, how XSLT templates work with each other, and gain an understanding of XSLT variables. Learning XSLT also explains how the XML Path Language (XPath) is used by XSLT and provides a glimpse of what the future holds for XSLT 2.0 and XPath 2.0.The ability to transform one XML vocabulary to another is fundamental to exploiting the power of XML. Learning XSLT is a carefully paced, example-rich introduction to XSLT that will have you understanding and using XSLT on your own in no time.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Preface
    1. Who Should Read This Book?
    2. About the Examples
    3. XSLT and XPath Reference
    4. How This Book Is Organized
    5. Conventions Used in This Book
    6. Using Examples
    7. Comments and Questions
    8. Acknowledgments
  3. 1. Transforming Documents with XSLT
    1. 1.1. How XSLT Works
      1. 1.1.1. A Ridiculous XML Document
      2. 1.1.2. A First XSLT Stylesheet
        1. 1.1.2.1. The stylesheet element
        2. 1.1.2.2. The XSLT namespace
        3. 1.1.2.3. The output element
        4. 1.1.2.4. The template element
          1. 1.1.2.4.1. The root node
    2. 1.2. Using Client-Side XSLT in a Browser
      1. 1.2.1. The XML Stylesheet Processing Instruction
        1. 1.2.1.1. Attributes and pseudoattributes
    3. 1.3. Using apply-templates
      1. 1.3.1. Analysis of message.xml
        1. 1.3.1.1. The XML declaration
      2. 1.3.2. Running Xalan
      3. 1.3.3. More About Xalan C++
      4. 1.3.4. Using Other XSLT Processors
      5. 1.3.5. Using xRay2
    4. 1.4. Summary
  4. 2. Building New Documents with XSLT
    1. 2.1. Outputting Text
      1. 2.1.1. Using the text Element
        1. 2.1.1.1. The disable-output-escaping attribute
    2. 2.2. Literal Result Elements
      1. 2.2.1. Adding a Namespace Prefix
      2. 2.2.2. Literal Result Elements for HTML
        1. 2.2.2.1. The META tag
      3. 2.2.3. XHTML Literal Result Elements
        1. 2.2.3.1. Attribute value templates
        2. 2.2.3.2. Applying namespaces
    3. 2.3. Using the Element Called element
      1. 2.3.1. The namespace attribute
    4. 2.4. Adding Attributes
      1. 2.4.1. Reusing a Set of Attributes
        1. 2.4.1.1. Chaining attribute sets
    5. 2.5. Outputting Comments
    6. 2.6. Outputting Processing Instructions
      1. 2.6.1. Mixed Content
      2. 2.6.2. Using Multiple Template Rules
        1. 2.6.2.1. What can go in a template rule?
      3. 2.6.3. Creating the PI and Putting It to Work
    7. 2.7. One Final Example
    8. 2.8. Summary
  5. 3. Controlling Output
    1. 3.1. The Output Method
      1. 3.1.1. The Default Output Methods
        1. 3.1.1.1. Default HTML output
        2. 3.1.1.2. Default XML output
    2. 3.2. Outputting XML
      1. 3.2.1. The XML Declaration
        1. 3.2.1.1. Omitting the XML declaration
        2. 3.2.1.2. The encoding declaration
          1. 3.2.1.2.1. ISO/IEC 8859
          2. 3.2.1.2.2. UTF-8 and UTF-16
          3. 3.2.1.2.3. The Byte Order Mark
      2. 3.2.2. Unicode and the Command Shell Window
      3. 3.2.3. Using Character Map and UniPad
        1. 3.2.3.1. Entities and text declarations
        2. 3.2.3.2. The standalone declaration
        3. 3.2.3.3. XML version information
      4. 3.2.4. Controlling Document Type Declarations
        1. 3.2.4.1. Validation with transformation
        2. 3.2.4.2. Adding a document type declaration with a system identifier
        3. 3.2.4.3. Adding a document type declaration with a public identifier
        4. 3.2.4.4. Validating XHTML
      5. 3.2.5. Outputting CDATA Sections
    3. 3.3. Outputting HTML
    4. 3.4. Outputting Text
    5. 3.5. Using a QName Output Method
    6. 3.6. Media Types
    7. 3.7. Summary
  6. 4. Traversing the Tree
    1. 4.1. The XPath Data Model
      1. 4.1.1. XPath Nodes
      2. 4.1.2. A View of the Tree
      3. 4.1.3. What’s a Context?
    2. 4.2. Location Paths
    3. 4.3. Expressions
    4. 4.4. What Is a Pattern?
    5. 4.5. Predicates
      1. 4.5.1. Matching Multiple Nodes with a Pattern
    6. 4.6. Axes
      1. 4.6.1. Unabbreviated Syntax
      2. 4.6.2. Reaching Out of Context with Unabbreviated Syntax
    7. 4.7. Name and Node Tests
    8. 4.8. Doing the Math with Expressions
    9. 4.9. Summary
  7. 5. XPath and XSLT Functions
    1. 5.1. Boolean Functions
      1. 5.1.1. The lang( ) Function
    2. 5.2. Node-Set Functions
      1. 5.2.1. The id( ) Function
    3. 5.3. Number Functions
      1. 5.3.1. The sum( ) Function
      2. 5.3.2. The round( ) Function
    4. 5.4. String Functions
      1. 5.4.1. The concat( ) Function
      2. 5.4.2. The normalize-space( ), translate( ), and substring( ) Functions
      3. 5.4.3. The generate-id( ) Function
    5. 5.5. Summary
  8. 6. Copying Nodes
    1. 6.1. The copy Element
      1. 6.1.1. Adding Attributes with copy
      2. 6.1.2. The Identity Transform
    2. 6.2. The copy-of Element
    3. 6.3. Copying Nodes from Two Documents
    4. 6.4. Summary
  9. 7. Using Variables and Parameters
    1. 7.1. Defining Variables and Parameters
      1. 7.1.1. Defining Default Values for Parameters
      2. 7.1.2. Defining Values with Expressions and Templates
        1. 7.1.2.1. Using the select attribute to define variables
        2. 7.1.2.2. Using result tree fragments to define variables
    2. 7.2. Using Variables
    3. 7.3. Using Parameters
      1. 7.3.1. Passing in a Parameter with Xalan
      2. 7.3.2. Passing in a Parameter with Instant Saxon
    4. 7.4. Invoking Templates with Parameters
    5. 7.5. Using Result Tree Fragments
    6. 7.6. Summary
  10. 8. Sorting Things Out
    1. 8.1. Simple Ascending Sort
    2. 8.2. Reversing the Sort
    3. 8.3. By the Numbers
    4. 8.4. Multiple Sorts
    5. 8.5. The lang and case-order Attributes
    6. 8.6. Summary
  11. 9. Numbering Lists
    1. 9.1. Numbered Lists
      1. 9.1.1. The number Element
      2. 9.1.2. The count Attribute
      3. 9.1.3. More on Formatting
    2. 9.2. Alphabetical Lists
      1. 9.2.1. Using Uppercase
      2. 9.2.2. Longer Alphabetical Lists
    3. 9.3. Roman Numerals
      1. 9.3.1. Uppercase Roman Numerals
    4. 9.4. Inserting an Individual Formatted Value
    5. 9.5. Numbering Levels
      1. 9.5.1. Counting on Multiple Levels
      2. 9.5.2. More Depth
      3. 9.5.3. Counting on Any Level
    6. 9.6. The from Attribute
    7. 9.7. The lang and letter-value Attributes
    8. 9.8. More Help with Formatted Numbers
    9. 9.9. Summary
  12. 10. Templates
    1. 10.1. Template Priority
      1. 10.1.1. The priority Attribute
    2. 10.2. Calling a Named Template
      1. 10.2.1. Using the name and match Attributes Together
    3. 10.3. Using Templates with Parameters
    4. 10.4. Modes
    5. 10.5. Built-in Template Rules
    6. 10.6. Summary
  13. 11. Using Keys
    1. 11.1. A Simple Key
      1. 11.1.1. The key Element
      2. 11.1.2. The key( ) Function
    2. 11.2. More Than One Key
    3. 11.3. Using a Parameter with Keys
      1. 11.3.1. Passing in a Parameter to the Stylesheet
    4. 11.4. Cross-Referencing with Keys
    5. 11.5. Grouping with Keys
    6. 11.6. Summary
  14. 12. Conditional Processing
    1. 12.1. The if Element
    2. 12.2. The choose and when Elements
      1. 12.2.1. The otherwise Element
      2. 12.2.2. Processing More Than One Kind of Document
    3. 12.3. Summary
  15. 13. Working with Multiple Documents
    1. 13.1. Including Stylesheets
    2. 13.2. Importing Stylesheets
      1. 13.2.1. Import Tree
      2. 13.2.2. Applying Imports
    3. 13.3. Using the document( ) Function
    4. 13.4. Summary
  16. 14. Alternative Stylesheets
    1. 14.1. A Literal Result Element Stylesheet
      1. 14.1.1. Pull and Push Stylesheets
      2. 14.1.2. A Literal XHTML Stylesheet
    2. 14.2. An Embedded Stylesheet
    3. 14.3. Aliasing a Namespace
    4. 14.4. Excluding Namespaces
    5. 14.5. Summary
  17. 15. Extensions
    1. 15.1. Xalan, Saxon, and EXSLT Extensions
    2. 15.2. Using a Saxon Extension Attribute
    3. 15.3. Result Tree Fragment to Node-Set
    4. 15.4. Using EXSLT
      1. 15.4.1. EXSLT’s exsl:node-set Function
    5. 15.5. Fallback Behavior
      1. 15.5.1. Invoking the Fallback Behavior
    6. 15.6. Checking for Extension Availability
    7. 15.7. Summary
  18. 16. XSLT 2.0 and XPath 2.0
    1. 16.1. New XSLT 2.0 Features
    2. 16.2. New XPath 2.0 Features
    3. 16.3. Multiple Result Trees
    4. 16.4. Using Regular Expressions
      1. 16.4.1. The matches( ) Function
      2. 16.4.2. The replace( ) Function
      3. 16.4.3. The analyze-string Element
    5. 16.5. Grouping in XSLT 2.0
    6. 16.6. Extension Functions
    7. 16.7. Summary
  19. 17. Writing an XSLT ProcessorInterface
    1. 17.1. Running an XSLT Processor from Java
      1. 17.1.1. The Moxie Source Code
      2. 17.1.2. Looking at the Moxie Code
      3. 17.1.3. Running Moxie
      4. 17.1.4. Compiling Moxie
      5. 17.1.5. Using Ant
      6. 17.1.6. Other Java Resources
    2. 17.2. Writing an XSLT Processor with C#
      1. 17.2.1. The Pax Code
      2. 17.2.2. Looking at the Pax Code
      3. 17.2.3. Running Pax
      4. 17.2.4. Compiling Pax
    3. 17.3. Summary
  20. 18. Parting Words
    1. 18.1. The Ox Documentation Tool
    2. 18.2. Signing Off
  21. A. XSLT Processors
    1. A.1. Installing and Running XSLT Processors
      1. A.1.1. Installing and Running Java
        1. A.1.1.1. Setting the path variable
          1. A.1.1.1.1. The path environment variable on Windows
          2. A.1.1.1.2. The path environment variable on Unix
        2. A.1.1.2. Running the Java compiler
      2. A.1.2. Using the Classpath
        1. A.1.2.1. The jar method
      3. A.1.3. Installing and Running Instant Saxon
        1. A.1.3.1. Downloading Instant Saxon
        2. A.1.3.2. Running Instant Saxon
      4. A.1.4. Installing and Running Saxon (Full Java Version)
        1. A.1.4.1. Downloading Saxon
        2. A.1.4.2. Running Saxon
        3. A.1.4.3. Using a Windows batch file with Saxon
        4. A.1.4.4. Using a Unix shell script with Saxon
      5. A.1.5. Installing and Running MSXSL
        1. A.1.5.1. Downloading MSXSL
        2. A.1.5.2. Running MSXSL
      6. A.1.6. Installing and Running Xalan C++
        1. A.1.6.1. Downloading and installing Xalan C++
        2. A.1.6.2. Setting the path variable for Xalan on Windows
        3. A.1.6.3. Setting the path variable for Xalan on a Unix platform
        4. A.1.6.4. Running Xalan C++
    2. A.2. Using jd.xslt
      1. A.2.1. Downloading and installing jd.xslt
        1. A.2.1.1. Running jd.xslt
      2. A.2.2. Using xmlspy
      3. A.2.3. Using xRay2
  22. Glossary
  23. Index
  24. About the Author
  25. Colophon
  26. Copyright

Product information

  • Title: Learning XSLT
  • Author(s): Michael Fitzgerald
  • Release date: November 2003
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596003272