Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
XSLT Cookbook, 2nd Edition
SPECIAL OFFER: Upgrade this ebook with O’Reilly
A Note Regarding Supplemental Files
Preface
Structure of This Book
Conventions Used in This Book
Using Code Examples
Safari Enabled
How to Contact Us
Acknowledgments
Second Edition Acknowledgments
First Edition Acknowledgments
1. XPath
Introduction
1.1. Effectively Using Axes
Problem
Solution
Child and descendant axes
Sibling axes
Parent and ancestor axes
Preceding and following axes
Discussion
1.2. Filtering Nodes
Problem
Solution
Discussion
1.3. Working with Sequences
Problem
Solution
XPath 1.0
XPath 2.0
Discussion
1.4. Shrinking Conditional Code with If Expressions
Problem
Solution
XPath 1.0
XPath 2.0
Discussion
1.5. Eliminating Recursion with for Expressions
Problem
Solution
XPath 1.0
XPath 2.0
Aggregation
Mapping
Generating
Expanding
Joining
Discussion
1.6. Taming Complex Logic Using Quantifiers
Problem
Solution
XPath 1.0
XPath 2.0
Discussion
1.7. Using Set Operations
Problem
Solution
XPath 1.0
XPath 2.0
Discussion
See Also
1.8. Using Node Comparisons
Problem
Solution
XPath 1.0
XPath 2.0
Discussion
1.9. Coping with XPath 2.0's Extended Type System
Problem
Solution
Discussion
1.10. Exploiting XPath 2.0's Extended Type System
Problem
Solution
Discussion
2. Strings
Introduction
2.1. Testing If a String Ends with Another String
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
2.2. Finding the Position of a Substring
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
2.3. Removing Specific Characters from a String
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 2.0
2.4. Finding Substrings from the End of a String
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
2.5. Duplicating a String N Times
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
See Also
2.6. Reversing a String
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
XSLT 2.0
2.7. Replacing Text
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
2.8. Converting Case
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 2.0
See Also
2.9. Tokenizing a String
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
See Also
2.10. Making Do Without Regular Expressions
Problem
Solution
Discussion
2.11. Exploiting Regular Expressions
Problem
Solution
Matching text patterns
Tokenizing stylized text
Replacing and augmenting text
Parsing text to convert to XML
Discussion
2.12. Using the EXSLT String Extensions
Problem
Solution
Discussion
See Also
3. Numbers and Math
Introduction
3.1. Formatting Numbers
Problem
Solution
Use xsl:decimal-format in conjunction with format-number()
Use xsl:number
Discussion
Formatting numbers into columns using a fixed number of decimal places
Formatting money like U.S. accountants
Formatting numbers for many European countries
Converting numbers to Roman numerals
Creating column numbers like a spreadsheet
Formatting numbers using Arabic characters
3.2. Rounding Numbers to a Specified Precision
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
3.3. Converting from Roman Numerals to Numbers
Problem
Solution
Discussion
3.4. Converting from One Base to Another
Problem
Solution
Discussion
3.5. Implementing Common Math Functions
Problem
Solution
XSLT 1.0
Absolute value: ckbk:abs(x)
Square root: ckbk:sqrt(x)
Logarithms: ckbk:log10(number), ckbk:log(number), and ckbk:logN(x,base)
Power: ckbk:power(base,power)
Factorial
XSLT 2.0
Discussion
3.6. Computing Sums and Products
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
XSLT 2.0
See Also
3.7. Finding Minimums and Maximums
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
3.8. Computing Statistical Functions
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
XSLT 2.0
3.9. Computing Combinatorial Functions
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
3.10. Testing Bits
Problem
Solution
Discussion
XSLT 2.0
4. Dates and Times
Introduction
See Also
4.1. Calculating the Day of the Week
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
4.2. Determining the Last Day of the Month
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
See Also
4.3. Getting Names for Days and Months
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
XSLT 2.0
See Also
4.4. Calculating Julian and Absolute Day Numbers from a Specified Date
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
4.5. Calculating the Week Number for aSpecified Date
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
See Also
4.6. Working with the Julian Calendar
Problem
Solution
Discussion
4.7. Working with the ISO Calendar
Problem
Solution
Discussion
See Also
4.8. Working with the Islamic Calendar
Problem
Solution
Discussion
See Also
4.9. Working with the Hebrew Calendar
Problem
Solution
Discussion
4.10. Formatting Dates and Times
Problem
Solution
XSLT 2.0
Discussion
XSLT 1.0
XSLT 2.0
The date-format declaration
The picture string
4.11. Determining Secular and Religious Holidays
Problem
Solution
Discussion
5. Selecting and Traversing
Introduction
5.1. Ignoring Duplicate Elements
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
XSLT 2.0
See Also
5.2. Selecting All but a Specific Element
Problem
Solution
Discussion
See Also
5.3. Selecting Nodes by Context
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
See Also
5.4. Performing a Preorder Traversal
Problem
Solution
Discussion
5.5. Performing a Postorder Traversal
Problem
Solution
Discussion
5.6. Performing an In-Order Traversal
Problem
Solution
Discussion
5.7. Performing a Level-Order Traversal
Problem
Solution
Discussion
5.8. Processing Nodes by Position
Problem
Solution
Discussion
XSLT 2.0
See Also
6. Exploiting XSLT 2.0
Introduction
6.1. Convert Simple Named Templates to XSLT Functions
Problem
Solution
Discussion
6.2. Prefer for-each-group over Muenchian Method of Grouping
Problem
Solution
Group by values (group-by="expression")
Group by adjacent nodes (group-adjacent="expression")
Group by starting node (group-starting-with="pattern")
Group by ending node (group-ending-with="pattern")
Discussion
6.3. Modularizing and Modes
Problem
Solution
Discussion
6.4. Using Types for Safety and Precision
Problem
Solution
Use the as attribute on elements that hold or return data.
Use the type attribute on elements that create data.
Discussion
6.5. Avoiding 1.0 to 2.0 Porting Pitfalls
Problem
Solution
Sequences do not transparently convert to atomic items
Types do not transparently convert to other types
Extra parameters are not ignored
Stricter semantic checking will cause errors on questionable usage
Discussion
6.6. Emulating Object-Oriented Reuse and Design Patterns
Problem
Solution
Discussion
Template method
Chain of responsibility
Decorator
6.7. Processing Unstructured Text with Regular Expressions
Problem
Solution
Discussion
6.8. Solving Difficult Serialization Problems with Character Maps
Problem
Solution
See Also
6.9. Outputting Multiple Documents
Problem
Solution
Discussion
See Also
6.10. Handling String Literals Containing Quote Characters
Problem
Solution
Discussion
6.11. Understanding the New Capabilities of Old XSLT 1.0 Features
Problem
Solution
xsl:apply-templates
xsl:attribute
xsl:call-template
xsl:comment
xsl:copy and xsl:copy-of
xsl:element
xsl:for-each
xsl:key
xsl:message
xsl:number
xsl:output
xsl:param
xsl:processing-instruction
xsl:strip-space
xsl:stylesheet
xsl:template
xsl:value-of
xsl:variable
xsl:with-param
current()
document()
function-available()
key()
system-property()
Discussion
7. XML to Text
Introduction
7.1. Dealing with Whitespace
Problem
Solution
Too much whitespace
Too little whitespace
Discussion
See Also
7.2. Exporting XML to Delimited Data
Problem
Solution
Create a CSV file from flat attribute-encoded elements
Create a CSV file from flat element-encoded data
Handle more complex mappings
XSLT 2.0
Discussion
7.3. Creating a Columnar Report
Problem
Solution
XSLT 2.0
Discussion
7.4. Displaying a Hierarchy
Problem
Solution
XSLT 2.0
Discussion
7.5. Numbering Textual Output
Problem
Solution
Number siblings sequentially
Start from a number other than one
Number elements globally
Number elements globally within a subcontext
Number hierarchically
Discussion
7.6. Wrapping Text to a Specified Width and Alignment
Problem
Solution
Discussion
See Also
8. XML to XML
Introduction
8.1. Converting Attributes to Elements
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
8.2. Converting Elements to Attributes
Problem
Solution
Discussion
XSLT 1.0
XSLT 2.0
8.3. Renaming Elements or Attributes
Problem
Solution
Discussion
8.4. Merging Documents with Identical Schema
Problem
Solution
Discussion
8.5. Merging Documents with Unlike Schema
Problem
Solution
Incorporate one document as a subpart of a parent document
Weave two documents together
Join elements from two documents to make new elements
Discussion
See Also
8.6. Splitting Documents
Problem
Solution
XSLT 1.0
Discussion
See Also
8.7. Flattening an XML Hierarchy
Problem
Solution
Discussion
8.8. Deepening an XML Hierarchy
Problem
Solution
Add structure based on existing data
Add structure to correct a poorly designed document
XSLT 2.0
Add structure based on existing data
Add structure to correct a poorly designed document
Discussion
Add structure based on existing data
Add structure to correct a poorly designed document
8.9. Reorganizing an XML Hierarchy
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
XSLT 2.0
See Also
9. Querying XML
Introduction
9.1. Performing Set Operations on Node Sets
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
See Also
9.2. Performing Set Operations on Node Sets Using Value Semantics
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
9.3. Determining Set Equality by Value
Problem
Solution
Discussion
9.4. Performing Structure-Preserving Queries
Problem
Solution
Discussion
9.5. Joins
Problem
Solution
Discussion
XSLT 1.0
XSLT 2.0
9.6. Implementing the W3C XML Query-UseCases in XSLT
Problem
Solution
Discussion
XSLT 1.0
XSLT 2.0
See Also
10. XML to HTML
Introduction
10.1. Using XSLT as a Styling Language
Problem
Solution
Discussion
See Also
10.2. Creating Hyperlinked Documents
Problem
Solution
Discussion
See Also
10.3. Creating HTML Tables
Problem
Solution
Discussion
XSLT 1.0
XSLT 2.0
10.4. Creating Frames
Problem
Solution
Discussion
See Also
10.5. Creating Data-Driven Stylesheets
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
10.6. Creating a Self-Contained HTML Transformation
Problem
Solution
Discussion
10.7. Populating a Form
Problem
Solution
Discussion
See Also
11. XML to SVG
Introduction
11.1. Transforming an Existing Boilerplate SVG
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
11.2. Creating Reusable SVG Generation Utilities for Graphs and Charts
Problem
Solution
XSLT 1.0
Axis generation
Bar generation
XY plots
Pie-slice generation
Open-Hi-Lo-Close plots
XSLT 2.0
Discussion
11.3. Creating a Tree Diagram
Problem
Solution
Discussion
See Also
11.4. Creating Interactive SVG-Enabled Web Pages
Problem
Solution
Discussion
See Also
12. Code Generation
Introduction
XSLT 2.0
12.1. Generating Constant Definitions
Problem
Solution
Discussion
12.2. Generating Switching Code
Problem
Solution
Discussion
12.3. Generating Message-Handling Stub Code
Problem
Solution
Discussion
12.4. Generating Data Wrappers
Problem
Solution
Discussion
12.5. Generating Pretty Printers
Problem
Solution
Discussion
12.6. Generating a Test Data-Entry Web Client
Problem
Solution
Discussion
12.7. Generating Test-Entry Web CGI
Problem
Solution
Discussion
12.8. Generating Code from UML Models via XMI
Problem
Solution
Discussion
12.9. Generating XSLT from XSLT
Problem
Solution
Discussion
See Also
13. Vertical XSLT Application Recipes
Introduction
13.1. Converting Visio VDX Documents to SVG
Problem
Solution
Discussion
See Also
13.2. Working with Excel XML Spreadsheets
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
13.3. Generating XTM Topic Maps from UML Modelsvia XMI
Problem
Solution
Discussion
See Also
13.4. Generating Web Sites from XTM Topic Maps
Problem
Solution
Sorting algorithms
Programming languages
Root topic
Page elements and layout
Discussion
See Also
13.5. Serving SOAP Documentation from WSDL
Problem
Solution
Discussion
See Also
14. Extending and Embedding XSLT
Introduction
14.1. Saxon Extension Functions
XSLT 1.0 (Saxon Version 6.5.4)
XSLT 2.0 (Saxon Version 8.x)
14.2. Saxon Extension Elements
XSLT 1.0 (Saxon Version 6.5.4)
XSLT 2.0 (Saxon Version 8.x)
14.3. Xalan-Java 2 Extension Functions
XSLT 1.0 (Xalan-Java 2.6.2)
14.4. Java Extension Function Using the Class Format Namespace
14.5. Java Extension Function Using the Package Format Namespace
14.6. Java Extension Function Using the Java Format Namespace
14.7. Scripting Extension Function Using Inline Script Code
14.8. Xalan-Java 2 Extension Elements
14.9. Java Extension Element
14.10. Scripting Extension Elements
XSLT 2.0
14.11. MSXML Extension Functions
XSLT 1.0
XSLT 2.0
See Also
14.12. Using Saxon's and Xalan's Native Extensions
Problem
Solution
XSLT 1.0
You want to output to more than one destination
You want to split a complex transformation into a series of transformations in a pipeline
You want to work with dates and times
You need a more efficient implementation of set operations
You want extended information about a node in the source tree
You want to interact with a relational database
You want to dynamically evaluate an XPath expression created at runtime
You want to change the value of a variable
You want to write first-class extension functions in XSLT 1.0
XSLT 2.0
You want to get an XPath expression to the current node
You want to handle and recover from dynamic errors
Discussion
See Also
14.13. Extending XSLT with JavaScript
Problem
Solution
Discussion
See Also
14.14. Adding Extension Functions Using Java
Problem
Solution
Discussion
See Also
14.15. Adding Extension Elements Using Java
Problem
Solution
Discussion
See Also
14.16. Using XSLT from Perl
Problem
Solution
Discussion
See Also
14.17. Using XSLT from Java
Problem
Solution
Discussion
See Also
15. Testing and Debugging
Introduction
15.1. Using xsl:message Effectively
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
XSLT 1.0
15.2. Tracing the Flow of Your Stylesheet Through Its Input Document
Problem
Solution
XSLT 1.0
XSLT 2.0
Discussion
See Also
15.3. Automating the Insertion of Debug Output
Problem
Solution
Discussion
See Also
15.4. Including Embedded Unit Test Data in Utility Stylesheets
Problem
Solution
Discussion
15.5. Structuring Unit Tests
Problem
Solution
Discussion
See Also
15.6. Testing Boundary and Error Conditions
Problem
Solution
Boundary-condition testing
Error-condition testing
Discussion
16. Generic and Functional Programming
Introduction
Extending the Content of Global Variables
Using Template Tags
See Also
XSLT 1.0
XSLT 2.0
16.1. Creating Polymorphic XSLT
Problem
Solution
Discussion
See Also
16.2. Creating Generic Element Aggregation Functions
Problem
Solution
Discussion
See Also
16.3. Creating Generic Bounded Aggregation Functions
Problem
Solution
Discussion
16.4. Creating Generic Mapping Functions
Problem
Solution
Discussion
16.5. Creating Generic Node-Set Generators
Problem
Solution
Discussion
Index
About the Author
Colophon
SPECIAL OFFER: Upgrade this ebook with O’Reilly
← Prev
Back
Next →
← Prev
Back
Next →