did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780130404466

XSLT and XPATH A Guide to XML Transformations

by ;
  • ISBN13:

    9780130404466

  • ISBN10:

    0130404462

  • Edition: 1st
  • Format: Paperback
  • Copyright: 2001-07-26
  • Publisher: Prentice Hall
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $44.99

Summary

Preface

You've heard of XML; your manager wants you to use it in your applications. Now what?

You've used HTML, and you know what a tag is; you know that it is somehow related to XML. You may even know what XML is and what it does. What you may not know is that, while XML identifies and adds structure to the content of a document, it does not tell you anything about how to process that content, or how to do anything useful with it beyond storage. This is good news, because this means your content can be used for many different purposes.

There are many things you can use to process content once it is marked up using XML. However, we have chosen to talk about the only standard application that allows you to do many different things with it. With XSLT, you can add style to XML, convert it to other XML, or simply chop it up and regenerate it in a different form.

XSLT is the power behind the throne of XML. It assures that every level of every piece of XML data is accessible and reusable across platforms and forward in time. It is not an exaggeration to say that XSLT and its companion XPath are the very glue and mortar that hold together and build the endlessly varying applications of markup data for any industry, academy, or individual. XSLT is the fastest cure for the fear of having obsolescence in a data or information architecture design.

XSLT is easy to use. In fact, XSLT itself is XML. XSLT "speaks the language," or the syntax, of XML with a powerful vocabulary of programming-like features that are nonetheless easy to use, learn, and understand.

XSLT attempts to be a bridge to nonprogrammers, bringing the easily understood syntax of XML together with a powerful scripting mechanism and simple pathing approach to document navigation.

It is our belief-and our approach in writing this book-that both the experienced programmer and the newly trained markup technologist can become more comfortable with the potent set of tools for preserving, augmenting, updating, and delivering XML data-whether it's on the Web or your corporation's intranet or B2B.

If you are constantly wishing you had just a little more control over your information, this book will deliver that-and much more. In fact, by the end of the first chapter, you will be able to perform basic conversions from XML documents to HTML that will display in any Web browser. Subsequent chapters build upon and enhance that base of knowledge, matching examples with detailed explanations and providing focus upon commonly misunderstood areas.

When you read this book, have your computer handy. Take the time to load up one of the XSLT processors and work along as you read. Learning by doing is always best, especially with XSLT and XPath. Chapter 13 will show you how to install the software included on the CD. Each example in the book is found on the CD in the examples directory, organized by chapter.

XSLT is rewarding and creative to use. Be prepared to enjoy this learning experience. You will be surprised by how quickly productive use of this technology increases.

Why Should You Use XSLT?

Browsers display HTML, not general XML tags. You have to do something with the XML once you have it. Can you print with XML? Can you send XML to the Web? Can you browse XML? Yes, but not alone.

XSLT lets you convert XML to HTML, other types of XML or just plain text. With a little creativity, and the proper knowledge of XSLT, you can generate practically any form of output from XML.

XSLT provides quick, easy solutions to all XML transformation issues. However, the designers of XSLT did not intend for you to use the specification without additional help.

"This book, along with the proper tools, is what is required for XML to succeed with the average business application."

—Sharon Adler, Co-Chair W3C XSL Working Group

The latest version of XSLT (for which this book is written) is 1.0. There are many additional features that are being considered by the W3C XSL committee, and version 2.0 promises to add some of these new features, as well as provide support for XML Schema, XML Query, and others.

Who Is This Book For?

This book is for anyone who works with electronic data and wants to enable XML transformations without a difficult programming language learning curve. If you are comfortable working with SGML, XML, or even HTML, you will benefit greatly from the common markup syntax.

Some people may find XSLT difficult because it is not a procedural programming language. Most programming languages have a very structured, concise syntax. The syntax of XSLT is XML and is designed to be human readable and easily understandable. You must have some knowledge of markup before using XSLT.

Some people may find XSLT difficult to use because it does not provide solutions to every transformation situation. For example, you cannot use XSLT to convert text to XML. There are situations when additional processing may be required. However, for most of your day-to-day XML transformations, XSLT is the tool of choice.

Organization

The book is organized to build a base of knowledge that will be added to chapter by chapter. Basic XSLT concepts and a brief overview of XML are covered in Chapter 1. The remainder of the chapters add functionality as required when creating stylesheets. The more complex the problem, the later it is covered.

Chapter 1 provides everything you need to know about XML and XSLT in a nutshell. This chapter gives a good overview with minimum syntax, and can be used by people at any level of markup experience as a review or for general information.

Chapter 2 covers stylesheet concepts that are crucial to understanding XSLT, as well as general stylesheet terminology.

Chapter 3 adds more concepts, a little more explanation and usage, and an in-depth study of templates to the basics covered in Chapters 1 and 2.

Chapter 4 defines and explains XPath expressions and patterns.

Chapter 5 covers XPath functions, which are crucial to using most of the elements in XSLT.

Chapter 6 walks through the creation of new XML elements and attributes using several different methods.

Chapter 7 discusses the use of multiple stylesheets by including and importing them, as well as a discussion on template priority.

Chapter 8 shows how to work with variables and parameters.

Chapter 9 covers anything that is in some way iterative or conditional, as well as the utilities required to copy XML from the input to the output.

Chapter 10 details the options for controlling output types, as well as stripping and preserving whitespace, and generating error messages.

Chapter 11 covers XSLT functions and their related elements, including importing external XML documents with the document() function, and using keys with <xsl:key>.

Chapter 12 discusses extensions, processors, and Java, as well as three "commercial" XSLT processors.

Chapter 13 describes three "freeware" processors: Xalan, Saxon, and XT, along with installation instructions and extension implementations.

There are three appendices that cover a variety of topics and case studies, as well as contributed material.

Versions

This book is written according to XSL Transformations (XSLT) Version 1.0, XML Path Language (XPath) Version 1.0, and Extensible Markup Language (XML) 1.0. Additional reference material came from Namespaces in XML REC-xml-names-19990114.

The version of James Clarks' XT used for the tests in this book is 19991105. The version of Michael Kay's Saxon used is 6.2.2.

Author Biography

JOHN ROBERT GARDNER, Ph.D., is an Architect with Sun Microsystems, Inc., a leading provider of industrial-strength hardware, software, and services that power the Internet and B2B.

ZARELLA L. RENDON is Senior Applications Engineer and co-founder of ISOGEN International, a leading provider of XML and SGML solutions. She is a member of the W3C XSL Working Group.

Table of Contents

Preface xv
Acknowledgments xxi
Anatomy of an XSLT Stylesheet
2(22)
What Is Markup?
4(2)
Markup Grows on Trees
4(2)
What Is XSLT?
6(1)
What Is XPath?
7(1)
The XSLT Stylesheet
7(1)
XSLT Stylesheet Concepts
8(6)
Using XSLT to Convert XML to HTML
10(4)
Terminology for XSLT
14(6)
The Root of the Matter
14(1)
Branching Out: Nodes
15(3)
Document Order
18(2)
Climbing `Round the Family Tree: Addressing in XSLT
20(4)
Fundamental Concepts of XSLT Stylesheets
24(20)
Boilerplates for XSLT Stylesheets
25(10)
Document Element: <xsl : stylesheet> or <xsl : transform>
26(5)
Literal Result Element (LRE) Stylesheet
31(2)
Children of the Document Element
33(2)
Embedding Stylesheets in XML Documents
35(1)
XSLT Stylesheet Terminology
36(5)
Stylesheet
37(1)
Stylesheet Element and Transform Element
37(1)
Result Tree
37(1)
Source Tree
38(1)
Whitespace
39(1)
Well-Formedness
40(1)
XML Components of XSLT Stylesheets
41(3)
The XML Declaration
41(1)
The Document Type Declaration
42(2)
Advanced Stylesheet Concepts
44(34)
Templates: The Building Blocks of Transformations
45(30)
Template Processing
46(2)
The <xsl : template> Top-Level Element
48(1)
The <xsl : template> Attributes
49(10)
Components of a Template
59(3)
The <xsl : apply - templates> Instruction Element
62(7)
The <xsl : call - template> Instruction Element
69(4)
The <xsl : value - of> Instruction Element
73(2)
Built-in Template Rules
75(3)
XPath Expressions
78(34)
XPath Syntax and Terminology
80(29)
Document Order in XPath
82(1)
The Context Node
82(1)
The Current Node
82(1)
Context Size
82(1)
Proximity Position
83(1)
Expressions
83(13)
Location Paths
96(2)
The Axis
98(7)
The Node Test
105(1)
The Predicate
106(3)
Abbreviations
109(3)
XPath Functions
112(76)
XPath Function Library
114(8)
XPath Function Library Terminology
116(6)
The Node-set Core Function Group
122(20)
The id ( ) Function
124(3)
The local - name ( ) Function
127(3)
The name ( ) Function
130(2)
The namespace - uri ( ) Function
132(3)
The last ( ) Function
135(2)
The Position ( ) Function
137(4)
The count ( ) Function
141(1)
String Core Function Group
142(29)
The string ( ) Function
143(2)
String Conversion Rules
145(3)
The concat ( ) Function
148(3)
The substring ( ) Function
151(4)
The substring - after ( ) Function
155(2)
The substring - before ( ) Function
157(2)
The normalize - space ( ) Function
159(2)
The translate ( ) Function
161(4)
The contains ( ) Function
165(3)
The starts - with ( ) Function
168(2)
The string - length ( ) Function
170(1)
Boolean Core Function Group
171(8)
The boolean ( ) Function
172(2)
Boolean Conversion Rules
174(1)
The false ( ) Function
174(1)
The true ( ) Function
175(1)
The lang ( ) Function
175(1)
The not ( ) Function
176(3)
Number Core Function Group
179(9)
The number ( ) Function
180(1)
Number Conversion Rules
180(2)
The sum ( ) Function
182(2)
The ceiling ( ) Function
184(1)
The floor ( ) Function
184(1)
The round ( ) Function
185(3)
Building New XML Documents with XSLT
188(36)
Creating Elements with LREs
190(1)
The <xsl : element> Instruction Element
191(3)
Creating Attributes with the <xsl : attribute> Instruction Element
194(7)
Using <xsl : attribute> with Namespaces
199(2)
The <xsl : attribute - set> Top-Level Element
201(5)
The name Attribute
202(1)
The use - attribute - sets Attribute
202(1)
Using Attribute Sets with <xsl : attribute - set>
203(3)
The <xsl : text> Instruction Element
206(7)
The disable - output - escaping Attribute
207(1)
Using <xsl : text> to Generate Text
208(3)
Generating Text without <xsl : text>
211(2)
Adding Attributes to LREs
213(3)
Attribute Value Templates
213(2)
Using <xsl : attribute> with LREs
215(1)
Using <xsl : attribute - set> and the xsl : use - attribute - sets Attribute with LREs
216(1)
Comments and Processing-Instructions
216(4)
The <xsl : comment> Instruction Element
218(1)
The <xsl : processing - instruction> Instruction Element
219(1)
Namespace Aliases
220(4)
Using Multiple Stylesheets
224(26)
Working with External Stylesheets
226(15)
The <xsl : include> Top-Level Element
226(4)
The <xsl : import> Top-Level Element
230(3)
Comparing the <xsl : import> and <xsl : include> Top-Level Elements
233(5)
The <xsl : apply - imports> Instruction Element
238(3)
Template Rule Processing and Priorities
241(9)
The Current Template Rule
241(1)
Conflict Resolution for Template Rules
242(3)
Overriding Import Template Rule Precedence and Priorities
245(5)
Working with Variables
250(20)
Declaring and Binding Variables
251(5)
The <xsl : variable> Top-Level Element
252(2)
The <xsl : param> Top-Level Element
254(1)
The <xsl : with - param> Element
255(1)
Result Tree Fragments
256(4)
Using Variable References
260(6)
Local vs. Global Variables
261(1)
Duplicate Declarations (Shadowing)
262(3)
Using the <xsl : with - param> Instruction Element
265(1)
Comparing <xsl : variable> and <xsl : param>
266(1)
Comparing <xsl : with - param> to <xsl : param> and <xsl : variable>
266(4)
Duplication, Iteration, and Conditional XSLT Elements
270(46)
The <xsl : copy - of> Instruction Element
272(2)
The <xsl : copy> Instruction Element
274(5)
The <xsl : for - each> Instruction Element
279(2)
The <xsl : sort> Element
281(11)
The Select Attribute of <xsl : sort>
283(2)
The data - type Attribute of <xsl : sort>
285(3)
The order Attribute of <xsl : sort>
288(1)
The case - order Attribute of <xsl : sort>
288(3)
The lang Attribute of <xsl : sort>
291(1)
The <xsl : if> Instruction Element
292(3)
The <xsl : choose> Instruction Element
295(4)
The <xsl : when> Conditional Element
296(1)
The <xsl : otherwise> Contingency Condition
297(1)
Using <xsl : when> and <xsl : otherwise> with <xsl : choose>
297(2)
The <xsl : number> Instruction Element
299(17)
The count Attribute of <xsl : number>
300(3)
The level Attribute of <xsl : number>
303(4)
The from Attribute of <xsl : number>
307(1)
The value Attribute
308(2)
The format Attribute
310(2)
The lang Attribute of <xsl : number>
312(1)
The letter - value Attribute
313(1)
The grouping - separator Attribute
313(1)
The grouping - size Attribute
314(1)
The <xsl : fallback> Instruction Element
314(2)
Controlling Output Options
316(30)
The <xsl : output> Top-Level Element
317(22)
Attributes for <xsl : output>
319(6)
Working with the xml Output File Method
325(7)
Working with the html Output File Method
332(6)
Working with the text Output File Method
338(1)
The <xsl : strip - space> and <xsl : preserve - space> Top-Level Elements
339(2)
Generating Error Messages and Logs
341(5)
The <xsl : message> Instruction Element
342(4)
XSLT Functions and Related XSLT Elements
346(44)
XSLT Function Groups
348(22)
Node-set XSLT Functions
349(11)
The current ( ) XSLT Function
360(1)
The key ( ) XSLT Function and the <xsl : key> Top-Level Element
361(9)
String XSLT Functions
370(12)
The system - property ( ) XSLT Function
370(2)
The generate - id ( ) XSLT Function
372(4)
The format - number ( ) XSLT Function
376(2)
The <xsl : decimal - format> Top-Level Element
378(4)
The unparsed - entity - uri ( ) XSLT Function
382(1)
The Boolean XSLT Function Group
382(8)
The element - available ( ) XSLT Function
383(4)
The function - available ( ) XSLT Function
387(3)
XSLT Processors, Extensions, and Java
390(28)
XSLT Processors
392(1)
Extension Elements and Functions
393(1)
Namespaces
393(11)
Theory of a Namespace
394(1)
Anatomy of a Namespace
395(1)
Default Namespace
396(1)
Qualified Names (QNames) and No-Colon Names (NCNames)
397(2)
The XSL Namespace
399(1)
Using Other Namespaces
400(1)
The Default XML Namespace
400(1)
Declaring the Extension Namespace and Its Applicability
401(1)
Processor Extensions, Java Additions, and Future W3C XSLT Specifications
402(1)
Conforming XSLT Processors and the OASIS XSLT Conformance Committee
402(2)
Java
404(6)
Getting Java Going on Your Solaris/UNIX, Macintosh, or Windows Machine
405(5)
Commercial XSLT Processors
410(8)
Sun Microsystems' XSLTC
411(1)
Oracle® XML Developer's Kit (XDK)
411(1)
Installing the Oracle XSL Processor
412(1)
Microsoft® MSXML
413(3)
Installing the Latest Microsoft XML Parser
416(2)
Xalan, Saxon, and XT
418(63)
Xalan
419(18)
Xalan-C++
420(6)
Xalan-J
426(1)
Using Xalan-J with Eric Lawson's GUI
426(1)
Installing the Basic Command-line Interface for Xalan-J
427(2)
Using Xalan-J with the Command-line Interface and Extensions
429(2)
Xalan-J Extensions
431(6)
Saxon
437(28)
Installing Full Saxon on Solaris/UNIX or Windows Java
438(1)
Installing Instant Saxon on Windows
439(1)
Saxon Options
440(2)
Saxon Command-line Parameters
442(1)
Saxon Extensions
443(22)
XT
465(10)
Installing XT for Windows
466(1)
Installing XT and XP on UNIX
466(1)
Installing XT and XP on Macintosh
467(3)
XT Extensions
470(3)
XT Limitations
473(2)
Generating Multiple Output Files Using Saxon, Xalan, or XT
475(6)
Appendix A Case Studies 481(42)
A.1 Lists
482(7)
A.1.1 Simple HTML Lists from XML with Literal Result Elements
482(1)
A.1.2 ASCII/Text-only Lists from XML Input
482(4)
A.1.3 Additional Text-only Formating from XML with <xsl : number>
486(3)
A.1.4 Multi-level Text Outline
489(1)
A.2 MARC Records: The ATLAS Project from ATLA-CERTR at Emory University
489(19)
A.3 The Harvard-Kyoto Classics Project with Vedic Literature
508(15)
Appendix B Grouping Using the Muenchian Method 523(4)
Jeni Tennison
Appendix C Using XSLT for the Artificial Intelligence ``N-Queens'' Problem 527(16)
Oren Ben-Kiki
C.1 Architecture
528(3)
C.1.1 Overall structure
528(1)
C.1.2 Solution representation
528(1)
C.1.3 Implementing Loops
529(2)
C.2 The Stylesheet
531(9)
C.2.1 Headers
531(2)
C.2.2 Compute the Set of Solutions
533(5)
C.2.3 Print a Solution
538(2)
C.3 Final notes
540(3)
Index 543

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

PrefaceYou've heard of XML; your manager wants you to use it in your applications. Now what?You've used HTML, and you know what a tag is; you know that it is somehow related to XML. You may even know what XML is and what it does. What you may not know is that, while XML identifies and adds structure to the content of a document, it does not tell you anything about how to process that content, or how to do anything useful with it beyond storage. This is good news, because this means your content can be used for many different purposes.There are many things you can use to process content once it is marked up using XML. However, we have chosen to talk about the only standard application that allows you to do many different things with it. With XSLT, you can add style to XML, convert it to other XML, or simply chop it up and regenerate it in a different form.XSLT is the power behind the throne of XML. It assures that every level of every piece of XML data is accessible and reusable across platforms and forward in time. It is not an exaggeration to say that XSLT and its companion XPath are the very glue and mortar that hold together and build the endlessly varying applications of markup data for any industry, academy, or individual. XSLT is the fastest cure for the fear of having obsolescence in a data or information architecture design.XSLT is easy to use. In fact, XSLT itself is XML. XSLT "speaks the language," or the syntax, of XML with a powerful vocabulary of programming-like features that are nonetheless easy to use, learn, and understand.XSLT attempts to be a bridge to nonprogrammers, bringing the easily understood syntax of XML together with a powerful scripting mechanism and simple pathing approach to document navigation.It is our belief-and our approach in writing this book-that both the experienced programmer and the newly trained markup technologist can become more comfortable with the potent set of tools for preserving, augmenting, updating, and delivering XML data-whether it's on the Web or your corporation's intranet or B2B.If you are constantly wishing you had just a little more control over your information, this book will deliver that-and much more. In fact, by the end of the first chapter, you will be able to perform basic conversions from XML documents to HTML that will display in any Web browser. Subsequent chapters build upon and enhance that base of knowledge, matching examples with detailed explanations and providing focus upon commonly misunderstood areas.When you read this book, have your computer handy. Take the time to load up one of the XSLT processors and work along as you read. Learning by doing is always best, especially with XSLT and XPath. Chapter 13 will show you how to install the software included on the CD. Each example in the book is found on the CD in the examples directory, organized by chapter.XSLT is rewarding and creative to use. Be prepared to enjoy this learning experience. You will be surprised by how quickly productive use of this technology increases. Why Should You Use XSLT?Browsers display HTML, not general XML tags. You have to do something with the XML once you have it. Can you print with XML? Can you send XML to the Web? Can you browse XML? Yes, but not alone.XSLT lets you convert XML to HTML, other types of XML or just plain text. With a little creativity, and the proper knowledge of XSLT, you can generate practically any form of output from XML.XSLT provides quick, easy solutions to all XML transformation issues. However, the designers of XSLT did not intend for you to use the specification without additional help. "This book, along with the proper tools, is what is required for XML to succeed with the average business application." --Sharon Adler, Co-Chair W3C XSL Working GroupThe latest version of XSLT (for w

Rewards Program