List of Examples

This list includes all the worked examples in the book: that is, the examples consisting of entire stylesheets, for which working code can be downloaded from It does not include the many examples that are provided as incomplete snippets.

The purpose of this list is to help you out when you know that you've seen an example somewhere that is relevant to your current problem, but you can't remember where you saw it.



A Hello World Stylesheet


This stylesheet creates an HTML containing a greeting (such as "Hello, World!") read from the source XML document.


Tabulating Word Frequencies


Given any XML document, this stylesheet produces a list of the words that appear in its text, giving the number of times each word appears, together with its frequency. This illustrates features in XSLT 2.0 for analyzing text using regular expressions, and for grouping based on common values.


Displaying a Poem


This stylesheet shows how to use template rules to render the text of a poem in HTML.




An XML Tree


This example shows how an XML document is represented as a tree in the data model.


Push Processing


This stylesheet shows the use of template rules to display a list of books in HTML, using one template rule for each different kind of node.


Controlling the Sequence of Processing


This example shows a refinement of the previous stylesheet in which the select attribute of <xsl:apply-templates> is used to control the sequence ...

Get XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.