beginning xslt 2.0

825 211 0
beginning  xslt  2.0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info Beginning XSLT 2.0 From Novice to Professional JENI TENNISON 3243chFM.qxd 6/20/05 10:06 AM Page i www.it-ebooks.info Beginning XSLT 2.0: From Novice to Professional Copyright © 2005 by Jeni Tennison All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN (pbk): 1-59059-324-3 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Chris Mills Technical Reviewer: Norman Walsh Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis, Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser Assistant Publisher: Grace Wong Project Manager: Kylie Johnston Copy Manager: Nicole LeClerc Copy Editor: Ami Knox Assistant Production Director: Kari Brooks-Copony Production Editor: Kelly Winquist Compositor and Artist: Kinetic Publishing Services, LLC Proofreader: Elizabeth Berry Indexer: Kevin Broccoli Cover Designer: Kurt Krames Manufacturing Manager: Tom Debolski Distributed to the book trade in the United States by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013, and outside the United States by Springer-Verlag GmbH & Co. KG, Tiergartenstr. 17, 69112 Heidelberg, Germany. In the United States: phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders@springer-ny.com, or visit http://www.springer-ny.com. Outside the United States: fax +49 6221 345229, e-mail orders@springer.de, or visit http://www.springer.de. For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley, CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indi- rectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com in the Downloads section. 3243chFM.qxd 6/20/05 10:06 AM Page ii www.it-ebooks.info iii Contents at a Glance About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi CHAPTER 1 Introducing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 CHAPTER 2 Creating HTML from XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 CHAPTER 3 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 CHAPTER 4 Conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 CHAPTER 5 Manipulating Atomic Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 CHAPTER 6 Variables and Parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 CHAPTER 7 Paths and Sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 CHAPTER 8 Result Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 CHAPTER 9 Sorting and Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 CHAPTER 10 IDs, Keys, and Numbering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 CHAPTER 11 Named Templates, Stylesheet Functions, and Recursion . . . . . . . 473 CHAPTER 12 Building XSLT Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499 CHAPTER 13 Schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 CHAPTER 14 Backwards Compatibility and Extensions . . . . . . . . . . . . . . . . . . . . . . 557 CHAPTER 15 Dynamic XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587 CHAPTER 16 Creating SVG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625 CHAPTER 17 Interpreting RSS with XSLT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669 APPENDIX A XPath Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697 APPENDIX B XSLT Quick Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747 INDEX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773 3243chFM.qxd 6/20/05 10:06 AM Page iii www.it-ebooks.info 3243chFM.qxd 6/20/05 10:06 AM Page iv www.it-ebooks.info v Contents About the Author. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv About the Technical Reviewer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi ■CHAPTER 1 Introducing XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Markup Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Extending HTML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Meta-Markup Languages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 XML: The Extensible Markup Language. . . . . . . . . . . . . . . . . . . . . . . . . 6 XML Rules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 XHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Elements in XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Attributes in XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Entities, Characters, and Encodings. . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Other Components of XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Moving to XHTML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Creating Markup Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Designing Markup Languages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Validating Markup Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Presenting XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Presenting XML with CSS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Associating Stylesheets with XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Limitations of CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 ■CHAPTER 2 Creating HTML from XML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 XSL: The Extensible Stylesheet Language. . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Using XSLT Processors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Using Saxon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Using MSXML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 3243chFM.qxd 6/20/05 10:06 AM Page v www.it-ebooks.info ■CONTENTSvi Simplified Stylesheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Literal Result Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 The <xsl:value-of> Instruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 The XSLT Namespace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Generating HTML Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Iterating Over Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Generating Attribute Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 ■CHAPTER 3 Templates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 XSLT Stylesheet Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Stylesheet Document Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Defining Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 The Node Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 XSLT Processing Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 The Initial Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 Matching Elements with Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 The Built-in Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Extending Stylesheets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Templates As Mapping Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Processing Document-Oriented XML . . . . . . . . . . . . . . . . . . . . . . . . . 104 Context-Dependent Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Resolving Conflicts Between Templates . . . . . . . . . . . . . . . . . . . . . . 117 Choosing the Next Best Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Processing with Push and Pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Using Templates with Modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Built-in Templates Revisited. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Chapter 4 Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Conditional Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Processing Optional Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 Using the Ancestry of Source XML . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Using the Location of Result XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Conditional Elements in XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Conditional Expressions in XPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 3243chFM.qxd 6/20/05 10:06 AM Page vi www.it-ebooks.info ■CONTENTS vii Testing Elements and Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Testing for Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Comparing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Testing with Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 Combining Tests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Filtering XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172 Testing Positions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 ■CHAPTER 5 Manipulating Atomic Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 Atomic Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 The Atomic Type Hierarchy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Creating Atomic Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Casting Between Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Manipulating Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Splitting and Recombining Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Reformatting Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Regular Expression Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Manipulating Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Formatting Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Manipulating Dates, Times, and Durations . . . . . . . . . . . . . . . . . . . . . . . . . 215 Extracting Components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Adjusting Timezones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 Formatting Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Manipulating Qualified Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 Manipulating URIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 ■CHAPTER 6 Variables and Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Defining Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Declaring a Variable’s Type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Referring to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Variable Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239 Sequence Constructors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Temporary Trees. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 3243chFM.qxd 6/20/05 10:06 AM Page vii www.it-ebooks.info ■CONTENTSviii Using Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 Declaring and Referring to Parameters . . . . . . . . . . . . . . . . . . . . . . . 260 Stylesheet Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Template Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 ■CHAPTER 7 Paths and Sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 Node Trees Revisited. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276 Accessing Information About Nodes. . . . . . . . . . . . . . . . . . . . . . . . . . 277 Namespaces in the Node Tree. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 Whitespace in Node Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290 Matching Nodes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Path Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Step Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Node Tests and Namespaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Selecting Nodes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 Axes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 Evaluating Location Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 Sequence Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 Creating Sequences with XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 Creating Sequences with XPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324 Testing Sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Iterating Over Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 Formatting Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340 ■CHAPTER 8 Result Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 Generating Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 Generating Elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 Generating Namespace Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 Generating Text Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 Generating Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366 Generating Comments and Processing Instructions . . . . . . . . . . . . 372 Creating Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 Copying Nodes and Branches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 Creating Result Documents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 3243chFM.qxd 6/20/05 10:06 AM Page viii www.it-ebooks.info ■CONTENTS ix Controlling Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 Output Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 Declaring Content Type Information . . . . . . . . . . . . . . . . . . . . . . . . . . 390 Controlling Output Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 ■CHAPTER 9 Sorting and Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Sorting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Sorting in Different Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 Sorting Nonalphabetically. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 Multiple Sorts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 Flexible Sorting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412 Grouping by Position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 Grouping in Sequence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 Multilevel Grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426 ■CHAPTER 10 IDs, Keys, and Numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 Searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 IDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440 Generating IDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 Numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 Getting the Number of an Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457 Numbering Sorted and Filtered Items . . . . . . . . . . . . . . . . . . . . . . . . 460 Formatting Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 Numbering Across a Document. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468 Generating Hierarchical Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . 469 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470 Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471 ■CHAPTER 11 Named Templates, Stylesheet Functions, and Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473 Named Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474 Stylesheet Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480 3243chFM.qxd 6/20/05 10:06 AM Page ix www.it-ebooks.info [...]... Compatibility and Extensions 557 Backwards Compatibility 558 Testing XSLT Processors 558 Upgrading XSLT 1.0 Stylesheets to XSLT 2.0 561 Running XSLT 2.0 Stylesheets in XSLT 1.0 Processors 564 Same-Version Compatibility 567 Testing Function Availability... and XSLT community for their questions, opinions, and encouragement: I learned all I know from you xix www.it-ebooks.info 3243chFM.qxd 6/20/05 10:06 AM Page xx www.it-ebooks.info 3243chFM.qxd 6/20/05 10:06 AM Page xxi Introduction W elcome to Beginning XSLT 2.0, a comprehensive introduction to the Extensible Stylesheet Language: Transformations 2.0 This book introduces you to transforming XML with XSLT. .. that the result of the transformation is as it should be All this chapter will be new to XSLT 1.0 users • Chapter 14, “Backwards Compatibility and Extensions”: This chapter discusses how to write stylesheets that can be run with both XSLT 1.0 and XSLT 2.0 processors and how to deal with partial implementations of XSLT 2.0 It also discusses the use of extension attributes, functions, and instructions that... (http://www.oxygenxml.com/), which also provides XSLT debugging facilities In order to run the XSLT transformations in this book, you will need at least one XSLT 2.0 processor At the moment, that means getting hold of Saxon-B (currently version 8.4), available from http://saxon.sourceforge.net/ To run the examples in Chapter 13, you will need a Schema-Aware XSLT 2.0 processor, which at the moment means Saxon-SA... to carry out a series of XSLT instructions You’ll learn how to use recursion (when a template or function calls itself ) within XSLT Here you’ll develop a number of utility templates or functions that allow you to perform sophisticated calculations XSLT 1.0 users will find the ability to create user-defined functions with XSLT code particularly helpful • Chapter 12, “Building XSLT Applications”: This... specializing in XSLT and XML schema development She trained as a knowledge engineer, gaining a PhD in collaborative ontology development, and since becoming a consultant has worked in a wide variety of areas, including publishing, water monitoring, and financial services She is author of XPath and XSLT On The Edge (Hungry Minds, 2001) and Beginning XSLT (Wrox, 2002) and one of the founders of the EXSLT initiative... Language: Transformations 2.0 This book introduces you to transforming XML with XSLT 2.0, helping you to create tailored presentations for all the information you have accessible as XML I wrote this book, like Beginning XSLT, based on my own experience as an XSLT user, but also based on my familiarity, from training people in XSLT, with the practical and conceptual hurdles that newcomers often face My aim... XPath 2.0 and the new facilities in XSLT that make tasks such as text processing, grouping, and creating multiple documents much easier Although much will look familiar, there are also some fundamental changes in the XPath data model and the XSLT processing model that may take you by surprise How This Book Is Structured This book starts gently, introducing XML and XSLT bit by bit and gradually demonstrating... Expression Syntax 738 www.it-ebooks.info 3243chFM.qxd 6/20/05 10:06 AM Page xiii ■CONTENTS ■ APPENDIX B XSLT Quick Reference 747 XSLT Elements 747 XSLT Attributes 770 ■ INDEX ... 567 Testing Instruction Availability 568 Excluding Portions of a Stylesheet 569 Sending Messages to the User in XSLT 2.0 572 Extensions to XSLT and XPath 574 Extension Functions 574 Extensions to Attribute Values . www.it-ebooks.info Beginning XSLT 2. 0 From Novice to Professional JENI TENNISON 324 3chFM.qxd 6 / 20 /05 10: 06 AM Page i www.it-ebooks.info Beginning XSLT 2. 0: From Novice to Professional Copyright © 20 05 by. . . . . . . . . . . . . . . . . . . . . . . . . . 773 324 3chFM.qxd 6 / 20 /05 10: 06 AM Page iii www.it-ebooks.info 324 3chFM.qxd 6 / 20 /05 10: 06 AM Page iv www.it-ebooks.info v Contents About the Author . . . . . . . . . . . . . . . . . . . . . . . . . 773 324 3chFM.qxd 6 / 20 /05 10: 06 AM Page xiii www.it-ebooks.info 324 3chFM.qxd 6 / 20 /05 10: 06 AM Page xiv www.it-ebooks.info xv About the Author ■JENI

Ngày đăng: 05/05/2014, 13:12

Từ khóa liên quan

Mục lục

  • Beginning XSLT 2.0: From Novice to Professional

    • Table of Content

    • Chapter 1 Introducing XML

    • Chapter 2 Creating HTML from XML

    • Chapter 3 Templates

    • Chapter 4 Conditions

    • Chapter 5 Manipulating Atomic Values

    • Chapter 6 Variables and Parameters.

    • Chapter 7 Paths and Sequences.

    • Chapter 8 Result Trees

    • Chapter 9 Sorting and Grouping

    • Chapter 10 IDs, Keys, and Numbering.

    • Chapter 11 Named Templates, Stylesheet Functions, and Recursion

    • Chapter 12 Building XSLT Applications

    • Chapter 13 Schemas

    • Chapter 14 Backwards Compatibility and Extensions

    • Chapter 15 Dynamic XSLT

    • Chapter 16 Creating SVG

    • Chapter 17 Interpreting RSS with XSLT.

    • Appendix A XPath Quick Reference

    • Appendix B XSLT Quick Reference

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan