Appendix B. The XSLT You Need for OpenDocument

The purpose of this appendix is to introduce you to XSLT. A knowledge of XSLT is essential if you wish to easily transform OpenDocument files to text, XHTML, or other XML formats; or to transform XML and XHTML documents to OpenDocument.

The idea behind XSLT is to transform an XML source document to an output document which may be XML or just plain text. The transformation is accomplished by feeding the source document to an XSLT transformation stylesheet.

XPath

Before we can get into the details of XSLT, we need to talk about how the transformation program views your document and refers to its elements, using a notation called XPath. Take a look at the document in Example B.1, “Sample XML Document” (with line numbers for reference only). XPath (conceptually) represents it as a tree like the one shown in Figure B.1, “Tree Representation of Sample Document”.

Example B.1. Sample XML Document

1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/css" href="style.css"?> 3 <!-- sample document --> 4 <document> 5 <para align="center"> Centered </para> 6 <para> Normal </para> 7 <index> 8 <item> 9 <para>Item one</para> 10 </item> 11 <item> 12 <para>Item two</para> 13 </item> 14 </index> 15 <endnote>The end</endnote> 16 </document>

This looks a lot like a file directory listing, and we will begin talking about XPath using this analogy. The highlighted item at the top of the diagram is called the root node of the tree, which corresponds to ...

Get OASIS OpenDocument Essentials: Using OASIS OpenDocument XML 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.