You are previewing Java and XSLT.
O'Reilly logo
Java and XSLT

Book Description

The power of XSLT is its ability to change the structure or format of any content that can be converted to XML. Java and XSLT shows you how to use XSL transformations in Java programs ranging from stand-alone applications to servlets. After an introduction to XSLT, the book focuses on applying transformations in some real-world scenarios, such as developing a discussion forum, transforming documents from one form to another, and generating content for wireless devices. Java and XSLT discusses several common XSLT processors and the TRAX API, paying special attention to performance issues. Although there's a brief tutorial introduction to the XSLT language, the primary focus of the book isn't on learning XSLT or developing stylesheets; it's on making practical use of transformations in Java code. The book covers:

  • Introduction and Technology Review

  • XSLT--The Basics

  • XSLT--Beyond The Basics

  • Java Web Architecture

  • Programmatic Interfaces to XSLT Processors

  • Using XSLT with Servlets

  • Discussion Forum Implementation

  • Advanced XSLT Web Techniques

  • Testing, Tuning and Development Environments

  • WAP and WML

  • XSLT and Wireless Examples

Table of Contents

  1. Java and XSLT
    1. Preface
      1. Audience
      2. Software and Versions
      3. Organization
      4. Conventions Used in This Book
      5. How to Contact Us
      6. Acknowledgments
    2. 1. Introduction
      1. Java, XSLT, and the Web
        1. What’s Wrong with HTML?
        2. Keeping Data and Presentation Separate
        3. The XSLT Solution
      2. XML Review
        1. SGML, XML, and Markup Languages
        2. XML Syntax
        3. Validation
        4. Java and XML
          1. SAX
          2. DOM
          3. JDOM
          4. JDOM and DOM interoperability
      3. Beyond Dynamic Web Pages
        1. Web Development Challenges
        2. Web Applications
        3. Nonbrowser Clients
          1. SOAP
        4. Wireless
      4. Getting Started
        1. Java XSLT Processor Choices
          1. XT
          2. LotusXSL
          3. SAXON
          4. JAXP
      5. Web Browser Support for XSLT
    3. 2. XSLT Part 1 -- The Basics
      1. XSLT Introduction
        1. An XSLT Example
        2. Trying It Out
      2. Transformation Process
        1. XML Tree Data Structure
        2. Recursive Processing with Templates
        3. Built-in Template Rules
        4. A Skeleton Stylesheet
      3. Another XSLT Example, Using XHTML
      4. XPath Basics
        1. How XSLT Uses XPath
        2. Axes
        3. Location Steps
        4. Location Paths
        5. Abbreviated Syntax
      5. Looping and Sorting
        1. Looping with <xsl:for-each>
        2. Sorting
        3. Looping and Sorting Examples
      6. Outputting Dynamic Attributes
        1. <xsl:attribute>
        2. Attribute Value Templates
        3. <xsl:attribute-set>
    4. 3. XSLT Part 2 -- Beyond the Basics
      1. Conditional Processing
        1. <xsl:if>
        2. <xsl:choose>, <xsl:when>, and <xsl:otherwise>
      2. Parameters and Variables
        1. <xsl:variable>
          1. Defining variables
          2. Using variables
        2. <xsl:call-template> and Named Templates
        3. <xsl:param>and <xsl:with-param>
        4. Incrementing Variables
        5. Template Modes
        6. <xsl:template> Syntax Summary
      3. Combining Multiple Stylesheets
        1. <xsl:include>
        2. <xsl:import>
      4. Formatting Text and Numbers
        1. Number Formatting
        2. Text Formatting
      5. Schema Evolution
        1. An Example XML File
        2. The Identity Transformation
        3. Transforming Elements and Attributes
        4. The Result File
      6. Ant Documentation Stylesheet
        1. Ant Basics
        2. Stylesheet Functionality
        3. The Complete Example
          1. Specifying XHTML output
          2. Creating the dependency graph
          3. Cleaning up dependency lists
    5. 4. Java-Based Web Technologies
      1. Traditional Approaches
        1. CGI
        2. Servlets as CGI Replacements
        3. JSP
        4. Template Engines
        5. The Hybrid Approach
      2. The Universal Design
        1. Web Frameworks
        2. Model-View-Controller
        3. XSLT Implementation
        4. Development and Maintenance Benefits of XSLT
      3. XSLT and EJB
        1. Tradeoffs
      4. Summary of Key Approaches
    6. 5. XSLT Processing with Java
      1. A Simple Example
        1. The Design
        2. Xalan 1 Implementation
        3. SAXON Implementation
        4. SAXON, Xalan, or TrAX?
      2. Introduction to JAXP 1.1
        1. JAXP 1.1 Implementation
        2. XSLT Plugability Layer
        3. The Transformer Class
        4. JAXP XSLT Design
      3. Input and Output
        1. System Identifiers, Files, and URLs
        2. JAXP I/O Design
        3. JAXP Stream I/O
        4. JAXP DOM I/O
        5. JAXP SAX I/O
          1. The approach
          2. Detailed CSV to SAX design
          3. Writing the custom parser
          4. Using the parser
          5. Conclusion
        6. Feeding JDOM Output into JAXP
          1. JDOM to SAX approach
          2. JDOM to DOM approach
          3. JDOM to text approach
      4. Stylesheet Compilation
        1. Templates API
        2. A Stylesheet Cache
    7. 6. Servlet Basics and XSLT
      1. Servlet Syntax
        1. Splash Screen Servlet Example
      2. WAR Files and Deployment
        1. WAR Files
        2. Deployment Descriptor
        3. Deploying SplashScreenServlet to Tomcat
        4. Servlet API Highlights
      3. Another Servlet Example
        1. Design
        2. XML and Stylesheets
        3. Source Code
        4. Deployment
        5. How to Compile, Deploy, and Run
        6. Locating Stylesheets with Initialization Parameters
      4. Stylesheet Caching Revisited
        1. Integration with the Stylesheet Cache
      5. Servlet Threading Issues
        1. Servlet Threading Model
        2. Thread Safety Tips
          1. Tip 1: Local variables are thread-safe
          2. Tip 2: Immutable objects are thread-safe
          3. Tip 3: Provide a single point of entry
          4. Tip 4: Understand the Templates interface
    8. 7. Discussion Forum
      1. Overall Process
        1. Requirements
        2. Screen Flow
      2. Prototyping the XML
        1. XHTML Prototypes
        2. XML Samples
        3. XSLT Stylesheets
      3. Making the XML Dynamic
        1. Domain Classes
        2. Data Adapter Layer
        3. JDOM XML Production
      4. Servlet Implementation
      5. Finishing Touches
        1. Deployment
        2. Ideas for Enhancements
    9. 8. Additional Techniques
      1. XSLT Page Layout Templates
      2. Session Tracking Without Cookies
        1. Servlet Session-Tracking API
        2. Session Tracking with Java and XSLT
      3. Identifying the Browser
      4. Servlet Filters
        1. Filter Overview
        2. XSLT Transformation Filter
        3. Closing Thoughts on Filters
      5. XSLT as a Code Generator
      6. Internationalization with XSLT
        1. XSLT Stylesheet Design
        2. Encodings
          1. Creating the XML and XSLT
        3. Putting It All Together
          1. XML data
          2. XSLT stylesheets
          3. Web page and servlet
        4. I18n Troubleshooting Checklist
    10. 9. Development Environment, Testing, and Performance
      1. Development Environment
        1. CLASSPATH Issues
          1. JAR hell?
          2. Sealing violations
          3. Other exceptions and errors
          4. Java optional packages
          5. Java IDEs
        2. Ant
          1. Installing Ant
          2. A typical Ant build file
          3. Transforming using Ant’s style task
        3. Tomcat
          1. Configuring Tomcat 3.2.x
          2. Configuring Tomcat 4.0.x
      2. Testing and Debugging
        1. JUnit
          1. An example unit test
          2. Running the test
        2. JAXP 1.1 Error Listeners
        3. A Custom XSLT Transformer GUI
          1. Screen shots
          2. Source code
      3. Performance Techniques
        1. Stress Testing with JMeter
        2. More Detailed Measurements
          1. Commercial options
          2. JVMPI
          3. Unit testing
        3. Using XSLT Processors Effectively
          1. Stylesheet caching
          2. Result caching
        4. Writing Effective XSLT
        5. Interacting with EJB
          1. Sending XML from EJBs
          2. Sending objects from EJBs
    11. 10. Wireless Applications
      1. Wireless Technologies
        1. Why Not HTML?
          1. Problems with HTML
          2. Limitations of current devices
      2. The Wireless Architecture
      3. Java, XSLT, and WML
        1. A WML Example
          1. WMLScript and WBMP
        2. Servlets and WML
          1. Identifying the client
          2. Setting the content type
        3. Movie Theater Example
          1. Storyboard
          2. XML data
          3. WML prototypes and screen shots
          4. Servlet implementation
          5. XSLT stylesheets
      4. The Future of Wireless
    12. A. Discussion Forum Code
    13. B. JAXP API Reference
      1. Package: javax.xml.parsers
      2. Package: javax.xml.transform
      3. Package: javax.xml.transform.dom
      4. Package: javax.xml.transform.sax
      5. Package: javax.xml.transform.stream
    14. C. XSLT Quick Reference
      1. <xsl:apply-imports>
      2. <xsl:apply-templates>
      3. <xsl:attribute>
      4. <xsl:attribute-set>
      5. <xsl:call-template>
      6. <xsl:choose>
      7. <xsl:comment>
      8. <xsl:copy>
      9. <xsl:copy-of>
      10. <xsl:decimal-format>
      11. <xsl:element>
      12. <xsl:fallback>
      13. <xsl:for-each>
      14. <xsl:if>
      15. <xsl:import>
      16. <xsl:include>
      17. <xsl:key>
      18. <xsl:message>
      19. <xsl:namespace-alias>
      20. <xsl:number>
      21. <xsl:otherwise>
      22. <xsl:output>
      23. <xsl:param>
      24. <xsl:preserve-space>
      25. <xsl:processing-instruction>
      26. <xsl:sort>
      27. <xsl:strip-space>
      28. <xsl:stylesheet>
      29. <xsl:template>
      30. <xsl:text>
      31. <xsl:transform>
      32. <xsl:value-of>
      33. <xsl:variable>
      34. <xsl:when>
      35. <xsl:with-param>
    15. Index
    16. Colophon