Details

XSLT 2.0 and XPath 2.0 Programmer's Reference


XSLT 2.0 and XPath 2.0 Programmer's Reference


4. Aufl.

von: Michael Kay

57,99 €

Verlag: Wiley
Format: PDF
Veröffentl.: 30.03.2010
ISBN/EAN: 9780470337523
Sprache: englisch
Anzahl Seiten: 1376

DRM-geschütztes eBook, Sie benötigen z.B. Adobe Digital Editions und eine Adobe ID zum Lesen.

Beschreibungen

Combining coverage of both XSLT 2.0 and XPath 2.0, this book is the definitive reference to the final recommendation status versions of both specifications. The authors start by covering the concepts in XSLT and XPath, and then delve into elements, operators, expressions with syntax, usage, and examples. Some of the specific topics covered include XSLT processing model, stylesheet structure, serialization, extensibility, and many others. In addition to online content that includes error codes, the book also has case studies you'll find applicable to your own challenges.
<p>Introduction xxix</p> <p>List of Examples xxxix</p> <p><b>Part I: Foundations</b></p> <p><b>Chapter 1: XSLT in Context 3</b></p> <p>What Is XSLT? 3</p> <p>How Does XSLT Transform XML? 7</p> <p>The Place of XSLT in the XML Family 21</p> <p>The History of XSL 26</p> <p>XSLT 2.0 as a Language 33</p> <p>Summary 40</p> <p><b>Chapter 2: The XSLT Processing Model 41</b></p> <p>XSLT: A System Overview 41</p> <p>The XDM Tree Model 45</p> <p>The Transformation Process 67</p> <p>Error Handling 80</p> <p>Variables and Expressions 80</p> <p>Summary 88</p> <p><b>Chapter 3: Stylesheet Structure 89</b></p> <p>Changes in XSLT 2.0 90</p> <p>The Modular Structure of a Stylesheet 90</p> <p>The <xsl:stylesheet> Element 98</p> <p>The <?xml-stylesheet?> Processing Instruction 99</p> <p>Embedded Stylesheets 102</p> <p>Declarations 104</p> <p>Instructions 108</p> <p>Simplified Stylesheets 125</p> <p>Writing Portable Stylesheets 127</p> <p>Whitespace 141</p> <p>Summary 148</p> <p><b>Chapter 4: Stylesheets and Schemas 151</b></p> <p>XML Schema: An Overview 151</p> <p>Declaring Types in XSLT 161</p> <p>Validating the Source Document 165</p> <p>Validating the Result Document 170</p> <p>Validating a Temporary Document 174</p> <p>Validating Individual Elements 176</p> <p>Validating Individual Attributes 179</p> <p>The default-validation Attribute 180</p> <p>Importing Schemas 180</p> <p>Using xsi:type 181</p> <p>Nillability 182</p> <p>Summary 183</p> <p><b>Chapter 5: Types 185</b></p> <p>What Is a Type System? 185</p> <p>Changes in 2.0 186</p> <p>Sequences 187</p> <p>Atomic Values 189</p> <p>Atomic Types 191</p> <p>Schema Types and XPath Types 217</p> <p>The Type Matching Rules 219</p> <p>Static and Dynamic Type Checking 221</p> <p>Summary 224</p> <p><b>Part II: XSLT and XPath Reference</b></p> <p><b>Chapter 6: XSLT Elements 227</b></p> <p>xsl:analyze-string 230</p> <p>xsl:apply-imports 237</p> <p>xsl:apply-templates 240</p> <p>xsl:attribute 254</p> <p>xsl:attribute-set 266</p> <p>xsl:call-template 271</p> <p>xsl:character-map 280</p> <p>xsl:choose 282</p> <p>xsl:comment 285</p> <p>xsl:copy 287</p> <p>xsl:copy-of 292</p> <p>xsl:decimal-format 298</p> <p>xsl:document 303</p> <p>xsl:element 306</p> <p>xsl:fallback 316</p> <p>xsl:for-each 322</p> <p>xsl:for-each-group 326</p> <p>xsl:function 344</p> <p>xsl:if 353</p> <p>xsl:import 357</p> <p>xsl:import-schema 368</p> <p>xsl:include 372</p> <p>xsl:key 376</p> <p>xsl:matching-substring 386</p> <p>xsl:message 386</p> <p>xsl:namespace 390</p> <p>xsl:namespace-alias 394</p> <p>xsl:next-match 399</p> <p>xsl:non-matching-substring 402</p> <p>xsl:number 403</p> <p>xsl:otherwise 420</p> <p>xsl:output 420</p> <p>xsl:output-character 424</p> <p>xsl:param 425</p> <p>xsl:perform-sort 437</p> <p>xsl:preserve-space 439</p> <p>xsl:processing-instruction 442</p> <p>xsl:result-document 445</p> <p>xsl:sequence 452</p> <p>xsl:sort 455</p> <p>xsl:strip-space 465</p> <p>xsl:stylesheet 465</p> <p>xsl:template 483</p> <p>xsl:text 492</p> <p>xsl:transform 495</p> <p>xsl:value-of 495</p> <p>xsl:variable 500</p> <p>xsl:when 515</p> <p>xsl:with-param 517</p> <p>Summary 519</p> <p><b>Chapter 7: XPath Fundamentals 521</b></p> <p>Notation 522</p> <p>Where to Start 523</p> <p>Expressions 524</p> <p>Lexical Constructs 527</p> <p>Primary Expressions 539</p> <p>Variable References 540</p> <p>Parenthesized Expressions 542</p> <p>Context Item Expressions 543</p> <p>Function Calls 544</p> <p>Conditional Expressions 551</p> <p>The XPath Evaluation Context 553</p> <p>Summary 568</p> <p><b>Chapter 8: XPath: Operators on Items 571</b></p> <p>Arithmetic Operators 571</p> <p>Value Comparisons 581</p> <p>General Comparisons 588</p> <p>Node Comparisons 593</p> <p>Boolean Expressions 594</p> <p>Summary 596</p> <p><b>Chapter 9: XPath: Path Expressions 599</b></p> <p>Examples of Path Expressions 600</p> <p>Changes in XPath 2.0 601</p> <p>Document Order and Duplicates 602</p> <p>The Binary «⁄» Operator 602</p> <p>Axis Steps 606</p> <p>Rooted Path Expressions 625</p> <p>The «⁄⁄» Abbreviation 626</p> <p>Combining Sets of Nodes 628</p> <p>Summary 632</p> <p><b>Chapter 10: XPath: Sequence Expressions 633</b></p> <p>The Comma Operator 634</p> <p>Numeric Ranges: The «to» Operator 636</p> <p>Filter Expressions 638</p> <p>The «for» Expression 640</p> <p>Simple Mapping Expressions 644</p> <p>The «some» and «every» Expressions 646</p> <p>Summary 651</p> <p><b>Chapter 11: XPath: Type Expressions 653</b></p> <p>Converting Atomic Values 654</p> <p>Sequence Type Descriptors 668</p> <p>The «instance of» Operator 677</p> <p>The «treatas» Operator 678</p> <p>Summary 680</p> <p><b>Chapter 12: XSLT Patterns 681</b></p> <p>Patterns and Expressions 681</p> <p>Changes in XSLT 2.0 682</p> <p>The Formal Definition 683</p> <p>An Informal Definition 685</p> <p>Conflict Resolution 686</p> <p>Matching Parentless Nodes 688</p> <p>The Syntax of Patterns 689</p> <p>Summary 708</p> <p><b>Chapter 13: The Function Library 709</b></p> <p>A Word about Naming 710</p> <p>Functions by Category 710</p> <p>Notation 712</p> <p>Code Samples 714</p> <p>Function Definitions 714</p> <p>Summary 913</p> <p><b>Chapter 14: Regular Expressions 915</b></p> <p>Branches and Pieces 916</p> <p>Quantifiers 916</p> <p>Atoms 917</p> <p>Subexpressions 918</p> <p>Back-References 918</p> <p>Character Groups 919</p> <p>Character Ranges 919</p> <p>Character Class Escapes 920</p> <p>Character Blocks 922</p> <p>Character Categories 924</p> <p>Flags 925</p> <p>Disallowed Constructs 927</p> <p>Summary 927</p> <p><b>Chapter 15: Serialization 929</b></p> <p>The XML Output Method 929</p> <p>The HTML Output Method 936</p> <p>The XHTML Output Method 939</p> <p>The Text Output Method 940</p> <p>Using the <xsl:output> declaration 940</p> <p>Character Maps 941</p> <p>Disable Output Escaping 945</p> <p>Summary 949</p> <p><b>Part III: Exploitation</b></p> <p><b>Chapter 16: Extensibility 953</b></p> <p>What Vendor Extensions Are Allowed? 954</p> <p>Extension Functions 955</p> <p>Keeping Extensions Portable 970</p> <p>Summary 971</p> <p><b>Chapter 17: Stylesheet Design Patterns 973</b></p> <p>Fill-in-the-Blanks Stylesheets 973</p> <p>Navigational Stylesheets 976</p> <p>Rule-Based Stylesheets 980</p> <p>Computational Stylesheets 985</p> <p>Summary 1000</p> <p><b>Chapter 18: Case Study: XMLSpec 1001</b></p> <p>Formatting the XML Specification 1002</p> <p>Preface 1004</p> <p>Creating the HTML Outline 1008</p> <p>Formatting the Document Header 1012</p> <p>Creating the Table of Contents 1019</p> <p>Creating Section Headers 1023</p> <p>Formatting the Text 1024</p> <p>Producing Lists 1028</p> <p>Making Cross-References 1029</p> <p>Setting Out the Production Rules 1033</p> <p>Overlay Stylesheets 1041</p> <p>Stylesheets for Other Specifications 1044</p> <p>Summary 1047</p> <p><b>Chapter 19: Case Study: A Family Tree 1049</b></p> <p>Modeling a Family Tree 1050</p> <p>Creating a Data File 1058</p> <p>Displaying the Family Tree Data 1072</p> <p>Summary 1098</p> <p><b>Chapter 20: Case Study: Knight’s Tour 1099</b></p> <p>The Problem 1099</p> <p>The Algorithm 1100</p> <p>Placing the Knight 1104</p> <p>Displaying the Final Board 1105</p> <p>Finding the Route 1106</p> <p>Running the Stylesheet 1112</p> <p>Observations 1112</p> <p>Summary 1113</p> <p><b>Part IV: Appendices</b></p> <p><b>Appendix A: XPath 2.0 Syntax Summary 1117</b></p> <p>Whitespace and Comments 1118</p> <p>Tokens 1118</p> <p>Syntax Productions 1119</p> <p>Operator Precedence 1122</p> <p><b>Appendix B: Error Codes 1123</b></p> <p>Functions and Operators (FO) 1124</p> <p>XPath Errors (XP) 1126</p> <p>XSLT Errors (XT) 1127</p> <p><b>Appendix C: Backward Compatibility 1139</b></p> <p>Stage 1: Backward-compatibility Mode 1140</p> <p>Stage 2: Setting version=‘‘2.0’’ 1142</p> <p>Stage 3: Adding a Schema 1145</p> <p>Summary 1145</p> <p><b>Appendix D: Microsoft XSLT Processors 1147</b></p> <p>MSXML 1147</p> <p>System.Xml 1158</p> <p>Summary 1161</p> <p><b>Appendix E: JAXP: The Java API for Transformation 1163</b></p> <p>The JAXP Parser API 1164</p> <p>The JAXP Transformation API 1169</p> <p>Examples of JAXP Transformations 1187</p> <p>Summary 1193</p> <p><b>Appendix F: Saxon 1195</b></p> <p>Using Saxon from the Command Line 1196</p> <p>Using Saxon from a Java Application 1199</p> <p>Using Saxon from a .NET Application 1203</p> <p>Saxon Tree Models 1205</p> <p>Extensibility 1205</p> <p>Collations 1207</p> <p>Extensions 1208</p> <p>The evaluate() Extension 1210</p> <p>Summary 1214</p> <p><b>Appendix G: Altova 1215</b></p> <p>Running from within XMLSpy 1215</p> <p>Conformance 1216</p> <p>Extensions and Extensibility 1217</p> <p>The Command Line Interface 1217</p> <p>Using the API 1218</p> <p>Summary 1220</p> <p><b>Appendix H: Glossary 1221</b></p> <p>Index 1233</p>
<b>Michael Kay</b> has been working in the XML field since 1997; he became a member of the XSL Working Group soon after the publication of XSLT 1.0, and took over as editor of the XSLT 2.0 specification in early 2001. He is also a member of the XQuery and XML Schema Working Groups, and is a joint editor of the XPath 2.0 specification. He is well known not only through previous editions of this book but also as the developer of the open source Saxon product, a pioneering implementation of XSLT 2.0, XPath 2.0, and XQuery 1.0.<br /><br />In 2004 the author formed his own company, Saxonica, to provide commercial software and services building on the success of the Saxon technology. Previously, he spent three years with Software AG, working with the developers of the Tamino XML server, an early XQuery implementation. His background is in database technology: after leaving the University of Cambridge with a Ph.D., he worked for many years with the (then) computer manufacturer ICL, developing network, relational, and objectoriented database software products as well as a text search engine, and held the position of ICL Fellow.
<p>This book is primarily a practical reference book for professional XSLT developers. It assumes no previous knowledge of the language, and many developers have used it as their first introduction to XSLT; however, it is not structured as a tutorial, and there are other books on XSLT that provide a gentler approach for beginners.</p> <p>The book does assume a basic knowledge of XML, HTML, and the architecture of the Web, and it is written for experienced programmers. There's no assumption that you know any particular language such as Java or Visual Basic, just that you recognize the concepts that all programming languages have in common.</p> <p>The book is suitable both for XSLT 1.0 users upgrading to XSLT 2.0, and for newcomers to XSLT. The book is also equally suitable whether you work in the Java or .NET world.</p> <p>As befits a reference book, a key aim is that the coverage should be comprehensive and authoritative. It is designed to give you all the details, not just an overview of the 20 percent of the language that most people use 80 percent of the time. It's designed so that you will keep coming back to the book whenever you encounter new and challenging programming tasks, not as a book that you skim quickly and then leave on the shelf. If you like detail, you will enjoy this book; if not, you probably won't.</p> <p>But as well as giving the detail, this book aims to explain the concepts, in some depth. It's therefore a book for people who not only want to use the language but who also want to understand it at a deep level.</p> <p>The book aims to tell you everything you need to know about the XSLT 2.0 language. It gives equal weight to the things that are new in XSLT 2.0 and the things that were already present in version 1.0. The book is about the language, not about specific products. However, there are appendices about Saxon (the author's own implementation of XSLT 2.0), about the Altova XSLT 2.0 implementation, and about the Java and Microsoft APIs for controlling XSLT transformations, which will no doubt be upgraded to handle XSLT 2.0 as well as 1.0. A third XSLT 2.0 processor, Gestalt, was released shortly before the book went to press, too late to describe it in any detail. But the experience of XSLT 1.0 is that there has been a very high level of interoperability between different XSLT processors, and if you can use one of them, then you can use them all.</p> <p>In the previous edition we split XSLT 2.0 and XPath 2.0 into separate volumes. The idea was that some readers might be interested in XPath alone. However, many bought the XSLT 2.0 book without its XPath companion and were left confused as a result; so this time, the material is back together. The XPath reference information is in self-contained chapters, so it should still be accessible when you use XPath in contexts other than XSLT.</p> <p>The book does not cover XSL Formatting Objects, a big subject in its own right. Nor does it cover XML Schemas in any detail. If you want to use these important technologies in conjunction with XSLT, there are other books that do them justice.</p> <p>This book contains twenty chapters and eight appendixes (the last of which is a glossary) organized into four parts. The following section outlines what you can find in each part, chapter, and appendix.</p> <p><b>Part I: Foundations:</b> The first part of the book covers essential concepts. You should read these before you start coding. If you ignore this advice, as most people do, then you read them when you get to that trough of despair when you find it impossible to make the language do anything but the most trivial tasks. XSLT is different from other languages, and to make it work for you, you need to understand how it was designed to be used.</p> <p><b>Chapter 1: XSLT in Context:</b> This chapter explains how XSLT fits into the big picture: how the language came into being and how it sits alongside other technologies. It also has a few simple coding examples to keep you alert.</p> <p><b>Chapter 2: The XSLT Processing Model:</b> This is about the architecture of an XSLT processor: the inputs, the outputs, and the data model. Understanding the data model is perhaps the most important thing that distinguishes an XSLT expert from an amateur; it may seem like information that you can't use immediately, but it's knowledge that will stop you making a lot of stupid mistakes.</p> <p><b>Chapter 3: Stylesheet Structure:</b> XSLT development is about writing stylesheets, and this chapter takes a bird's eye view of what stylesheets look like. It explains the key concepts of rule-based programming using templates, and explains how to undertake programming-in-the-large by structuring your application using modules and pipelines.</p> <p><b>Chapter 4: Stylesheets and Schemas:</b> A key innovation in XSLT 2.0 is that stylesheets can take advantage of knowledge about the structure of your input and output documents, provided in the form of an XML Schema. This chapter provides a quick overview of XML Schema to describe its impact on XSLT development. Not everyone uses schemas, and you can skip this chapter if you fall into that category.</p> <p><b>Chapter 5: The Type System:</b> XPath 2.0 and XSLT 2.0 offer strong typing as an alternative to the weak typing approach of the 1.0 languages. This means that you can declare the types of your variables, functions, and parameters, and use this information to get early warning of programming errors. This chapter explains the data types available and the mechanisms for creating user-defined types.</p> <p><b>Part II: XSLT and XPath Reference:</b> This section of the book contains reference material, organized in the hope that you can easily find what you need when you need it. It's not designed for sequential reading, though you might well want to leaf through the pages to discover what's there.</p> <p><b>Chapter 6: XSLT Elements:</b> This monster chapter lists all the XSLT elements you can use in a stylesheet, in alphabetical order, giving detailed rules for the syntax and semantics of each element, advice on usage, and examples. This is probably the part of the book you will use most frequently as you become an expert XSLT user. It's a "no stone unturned" approach, based on the belief that as a professional developer you need to know what happens when the going gets tough, not just when the wind is in your direction.</p> <p><b>Chapter 7: XPath Fundamentals:</b> This chapter explains the basics of XPath: the low-level constructs such as literals, variables, and function calls. It also explains the context rules, which describe how the evaluation of XPath expressions depends on the XSLT processing context in which they appear.</p> <p><b>Chapter 8: XPath: Operators on Items:</b> XPath offers the usual range of operators for performing arithmetic, boolean comparison, and the like. However, these don't always behave exactly as you would expect, so it's worth reading this chapter to see what's available and how it differs from the last language that you used.</p> <p><b>Chapter 9: XPath: Path Expressions:</b> Path expressions are what make XPath special; they enable you to navigate around the structure of an XML document. This chapter explains the syntax of path expressions, the 13 axes that you can use to locate the nodes that you need, and associated operators such as union, intersection, and difference.</p> <p><b>Chapter 10: XPath: Sequence Expressions:</b> Unlike XPath 1.0, in version 2.0 all values are sequences (singletons are just a special case). Some of the most important operators in XPath 2.0 are those that manipulate sequences, notably the <code>«for»</code> expression, which translates one sequence into another by applying a mapping.</p> <p><b>Chapter 11: XPath: Type Expressions:</b> The type system was explained in Chapter 5; this chapter explains the operations that you can use to take advantage of types. This includes the <code>«cast»</code> operation which is used to convert values from one type to another. A big part of this chapter is devoted to the detailed rules for how these conversions are done.</p> <p><b>Chapter 12: XSLT Patterns:</b> This chapter returns from XPath to a subject that's specific to XSLT. Patterns are used to define template rules, the essence of XSLT's rule-based programming approach. The reason for explaining them now is that the syntax and semantics of patterns depends strongly on the corresponding rules for XPath expressions.</p> <p><b>Chapter 13: The Function Library:</b> XPath 2.0 includes a library of functions that can be called from any XPath expression; XSLT 2.0 extends this with some additional functions that are available only when XPath is used within XSLT. The library has grown immensely since XPath 1.0. This chapter provides a single alphabetical reference for all these functions.</p> <p><b>Chapter 14: Regular Expressions:</b> Processing of text is an area where XSLT 2.0 and XPath 2.0 are much more powerful than version 1.0, and this is largely through the use of constructs that exploit regular expressions. If you're familiar with regexes from languages such as Perl, this chapter tells you how XPath regular expressions differ. If you're new to the subject, it explains it from first principles.</p> <p><b>Chapter 15: Serialization:</b> Serialization in XSLT means the ability to generate a textual XML document from the tree structure that's manipulated by a stylesheet. This isn't part of XSLT processing proper, so (following W3C’s lead) it's separated it into its own chapter. You can control serialization from the stylesheet using an <code></code>declaration, but many products also allow you to control it directly via an API.</p> <p><b>Part III: Exploitation:</b> The final section of the book is advice and guidance on how to take advantage of XSLT to write real applications. It's intended to make you not just a competent XSLT coder, but a competent designer too. The best way of learning is by studying the work of others, so the emphasis here is on practical case studies.</p> <p><b>Chapter 16: Extensibility:</b> This chapter describes the "hooks" provided in the XSLT specification to allow vendors and users to plug in extra functionality. The way this works will vary from one implementation to another, so we can't cover all possibilities, but one important aspect that the chapter does cover is how to use such extensions and still keep your code portable.</p> <p><b>Chapter 17: Stylesheet Design Patterns:</b> This chapter explores a number of design and coding patterns for XSLT programming, starting with the simplest "fill-in-the-blanks" stylesheet, and extending to the full use of recursive programming in the functional programming style, which is needed to tackle problems of any computational complexity. This provides an opportunity to explain the thinking behind functional programming and the change in mindset needed to take full advantage of this style of development.</p> <p><b>Chapter 18: Case Study: XMLSpec:</b> XSLT is often used for rendering documents, so where better to look for a case study than the stylesheets used by the W3C to render the XML and XSLT specifications, and others in the same family, for display on the web? The resulting stylesheets are typical of those you will find in any publishing organization that uses XML to develop a series of documents with a compatible look-and-feel.</p> <p><b>Chapter 19: Case Study: A Family Tree:</b> Displaying a family tree is another typical XSLT application. This example with semi-structured data—a mixture of fairly complex data and narrative text—that can be presented in many different ways for different audiences. It also shows how to tackle another typical XSLT problem, conversion of the data into XML from a legacy text-based format. As it happens, this uses nearly all the important new XSLT 2.0 features in one short stylesheet. But another aim of this chapter is to show a collection of stylesheets doing different jobs as part of a complete application.</p> <p><b>Chapter 20: Case Study: Knight's Tour:</b> Finding a route around a chessboard where a knight visits every square without ever retracing its steps might sound a fairly esoteric application for XSLT, but it's a good way of showing how even the most complex of algorithms are within the capabilities of the language. You may not need to tackle this particular problem, but if you want to construct an SVG diagram showing progress against your project plan, then the problems won't be that dissimilar.</p> <p><b>Part IV: Appendices:</b> <b>Appendix A: XPath 2.0 Syntax Summary:</b> Collects the XPath grammar rules and operator precedences into one place for ease of reference.</p> <p><b>Appendix B: Error Codes:</b> A list of all the error codes defined in the XSLT and XPath language specifications, with brief explanations to help you understand what's gone wrong.</p> <p><b>Appendix C: Backward Compatibility:</b> The list of things you need to look out for when converting applications from XSLT 1.0.</p> <p><b>Appendix D: Microsoft XSLT Processors:</b> Although the two Microsoft XSLT processors don't yet support XSLT 2.0, we thought many readers would find it useful to have a quick summary here of the main objects and methods used in their APIs.</p> <p><b>Appendix E: JAXP: the Java API for XML Processing:</b> JAXP is an interface rather than a product. Again, it doesn't have explicit support yet for XSLT 2.0, but Java programmers will often be using it in XSLT 2.0 projects, so the book includes an overview of the classes and methods available.</p> <p><b>Appendix F: Saxon:</b> At the time of writing Saxon (developed by the author of this book) provides the most comprehensive implementation of XSLT 2.0 and XPath 2.0, so its interfaces and extensions are covered in some detail.</p> <p><b>Appendix G: Altova:</b> Altova, the developers of XML Spy, have an XSLT 2.0 processor that can be used either as part of the development environment or as a freestanding component. This appendix gives details of its interfaces.</p> <p><b>Appendix H: Glossary<br /></b></p> <p><b>Note:</b> CD-ROM/DVD and other supplementary materials are not included as part of eBook file.</p>

Diese Produkte könnten Sie auch interessieren:

Domain Architectures
Domain Architectures
von: Daniel J. Duffy
PDF ebook
31,99 €