XSLT Other resources from O’Reilly Related titles oreilly.com XSLT Cookbook XQuery Learning XSLT Java & XML Schematron Developing Feeds with RSS and Atom XML Hacks XSLT 1.0 Pocket Reference Relax NG Unicode Explained XML in a Nutshell Learning XML oreilly.com is more than a complete catalog of O’Reilly books You'll also find links to news, events, articles, weblogs, sample chapters, and code examples oreillynet.com is the essential portal for developers interested in open and emerging technologies, including new platforms, programming languages, and operating systems Conferences O’Reilly Media, Inc brings diverse innovators together to nurture the ideas that spark revolutionary industries We specialize in documenting the latest tools and systems, translating the innovator’s knowledge into useful skills for those in the trenches Visit conferences.oreilly.com for our upcoming events Safari Bookshelf (safari.oreilly.com) is the premier online reference library for programmers and IT professionals Conduct searches across more than 1,000 books Subscribers can zero in on answers to time-critical questions in a matter of seconds Read the books on your Bookshelf from cover to cover or simply flip to the page you need Try it today for free SECOND EDITION Tomcat XSLT The Definitive Guide Jason Brittain and Ian F Darwin Doug Tidwell Beijing • Cambridge • Farnham • Kưln • Sebastopol • Taipei • Tokyo ™ XSLT, Second Edition by Doug Tidwell Copyright © 2008 O’Reilly Media, Inc All rights reserved Printed in the United States of America Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472 O’Reilly books may be purchased for educational, business, or sales promotional use Online editions are also available for most titles (http://safari.oreilly.com) For more information, contact our corporate/ institutional sales department: 800-998-9938 or corporate@oreilly.com Editor: Simon St.Laurent Production Editor: Sarah Schneider Proofreader: Mary Brady Indexer: Fred Brown Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: June 2008: August 2001: Second Edition First Edition Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc XSLT, the image of a Jabiru, and related trade dress are trademarks of O’Reilly Media, Inc Many of the designations uses by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and O’Reilly Media, Inc was aware of a trademark claim, the designations have been printed in caps or initial caps While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein ISBN: 978-0-596-52721-1 [C] 1213384691 To my family—my wonderful wife, Sheri Castle, and our amazing daughter, Lily—for their love, support, and understanding Nothing I would be possible or meaningful without them .and a special thanks to our dog, Domino, who frequently and selflessly pushed his fuzzy head between my hands and keyboard to protect me from carpal tunnel syndrome Good boy! Table of Contents Preface xi Getting Started The Design of XSLT XML Basics Installing XSLT Processors Summary The Obligatory Hello World Example 25 Goals of This Chapter Transforming Hello World How a Stylesheet Is Processed Stylesheet Structure Sample Gallery Summary 25 25 27 30 36 44 XPath: A Syntax for Describing Needles and Haystacks 45 The XPath Data Model Location Paths Attribute Value Templates Datatypes XPath Operators [2.0] Comments in XPath Expressions [2.0] Types of XSLT 2.0 Processors The XPath View of an XML Document Summary 4 20 24 46 55 66 67 71 102 104 104 112 Creating Output 113 Goals of This Chapter Generating Text Numbering Things Formatting Decimal Numbers 113 113 118 127 vii [2.0] Formatting Dates and Times Using and Dealing with Whitespace Summary Branching and Control Elements 145 Goals of This Chapter Branching Elements of XSLT Invoking Templates by Name Parameters Variables Using Recursion to Do Most Anything A Stylesheet That Emulates a for Loop Summary 205 215 219 228 243 Combining Documents 245 The document( ) Function The document( ) Function and Sorting Implementing Lookup Tables Grouping Across Multiple Documents [2.0] Using XSLT 2.0 to Simplify Things [2.0] The doc( ) and doc-available( ) Functions [2.0] The collection( ) Function [2.0] The unparsed-text( ) and unparsed-text-available( ) Functions Summary 181 194 198 204 Sorting and Grouping Elements 205 Sorting Data with [2.0] The Element Grouping Nodes [2.0] New Grouping Syntax in XSLT 2.0 Summary 145 145 151 152 167 169 174 179 Creating Links and Cross-References 181 Using the XML ID, IDREF, and IDREFS Datatypes XSLT’s Key Facility Generating Links in Unstructured Documents Summary 130 132 139 144 245 254 254 257 260 269 271 272 275 Extending XSLT 277 The XSLT Extension Mechanism [2.0] Creating New Functions with Example: Generating Multiple Output Files viii | Table of Contents 277 279 281 ... XSLT Other resources from O’Reilly Related titles oreilly. com XSLT Cookbook XQuery Learning XSLT Java & XML Schematron Developing Feeds with RSS and Atom XML Hacks XSLT 1.0 Pocket... Printing History: June 2008: August 2001: Second Edition First Edition Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc XSLT, the... help you make the most of XSLT, the Extensible Stylesheet Language for Transformations It covers both XSLT 1.0 and XSLT 2.0, along with versions 1.0 and 2.0 of XPath, the XML Path Language The two